wiki

Higher-kinded type

also: hkt, kind

A type that abstracts over a type constructor rather than over a type, so that Functor f can be instantiated at Maybe or at lists without naming their element types. It is what makes a single Monad class usable across every container instead of one class per shape.

Kinds classify types the way types classify values. has kind ; is not a type but a function on types, of kind . A higher-kinded type variable ranges over those functions rather than over types.

Functor abstracts over the container, not the element, which is why one class covers every shape.

class Functor f where -- f :: * -> *
fmap :: (a -> b) -> f a -> f b
instance Functor Maybe where
fmap _ Nothing = Nothing
fmap g (Just x) = Just (g x)
instance Functor (Either e) where -- partial application: Either e :: * -> *
fmap _ (Left e) = Left e
fmap g (Right x) = Right (g x)

Without it the hierarchy collapses into one class per container. It is also the feature whose absence is most felt elsewhere: OCaml has no higher-kinded variables, so the same abstraction is expressed with functors over modules, and Java and Go cannot express it at all.

referenced by

Constraint kinds

read more