A type class states which operations a type supports. It lets one function work across many types while still requiring the operations it needs. For example, equality is not assumed for every type: using `==` requires an `Eq` instance. section 5.1.3 section 1.1.1
ghci> :info Eq
type Eq :: * -> Constraint
class Eq a where
(==) :: a -> a -> Bool
(/=) :: a -> a -> Bool
{-# MINIMAL (==) | (/=) #-}
Inspect `Eq` in GHCi to see a class declaration, its equality operations, and the minimal implementation required for an instance. section 5.1.3
A constraint narrows an otherwise polymorphic type. `member :: Eq a => a -> [(a, b)] -> Bool` says that keys may have any type `a`, provided values of that type can be compared. Without the constraint, the compiler cannot justify the use of `==`. section 5.1.2 section 5.1.3
Read a type-class-based design in three parts:
- Declare the capability as a class and give the operations it promises. section 5.1.3 section 10.4.1
- Create an instance to implement that capability for a particular type. section 5.1.3 section 10.4.1
- Add a constraint when a generic function must rely on that capability. section 5.1.3
One conversion API for several pitch representations
`Pitchable` defines `toFrequency :: a -> Hz`. An `Hz` value converts with `id`; semitone distances calculate a frequency; chromatic notes first convert to semitones and then reuse that conversion. Callers use `toFrequency` without choosing a separate function for each representation. section 10.4.1
Type classes support practical extension points. A `Performer` class abstracts turning a performance into a signal so more noisemakers can be added later. The same pattern can generalize CSV operations and property-test input generation rather than hard-coding behavior for one data type. section 11.2.1 section 7.0 section 9.1.5
The terminology resembles object-oriented programming, but type classes are not objects to instantiate. Think instead in terms of declared operations, concrete instances, and constraints that make generic code safe to use. section 5.1.3


