Maybe and List are not types - they are
type constructors of kind * -> *. Type classes over HKTs
abstract over the container shape, not the contained type.
Functor, Applicative,
and Monad as type classes that apply to any container or effect
shape. Without HKTs, each container needs its own specialized map.
| Class | Key operation | What it adds |
|---|---|---|
Functor |
fmap :: (a->b) -> f a -> f b |
Map a pure function over a context |
Applicative |
(<*>) :: f (a->b) -> f a -> f b |
Apply a wrapped function to a wrapped value |
Monad |
(>>=) :: m a -> (a -> m b) -> m b |
Sequence: result of first computation affects second |
Iterator, Option,
and Result combinators (map, zip,
and_then). The Haskell type classes make the pattern explicit and
uniform across all types that satisfy the laws.
Eq,
Ord, Show, Functor, Monad are not
ad-hoc naming conventions but formal interfaces with mathematical laws that instances
must satisfy. Code written against these interfaces is correct for any conforming
type, now and in the future. The next chapter examines how immutability shapes the
data structures declarative programs rely on.