Kinds
Overview
Kinds are the types of types
Kinds classify Haskell types. Only well-kinded types are admissible.
The most important kind in Haskell is called * :
nearly all expressions in Haskell have types that have kind *
in particular, if you define an unparameterized datatype using data , it has kind *;
for now, think of kind * as the kind of potentially inhabited types, or as the kind of “fully applied” types
Kinds in GHCi
Haskell can infer kinds, just as it can infer types. And you can ask GHCi for the inferred kind of a type.
To obtain the inferred kind for a type term, type :k or :kind followed by the term at the GHCi prompt.
code:kind.hs
Int :: *
Char :: *
Maybe :: * -> *
IO :: * -> *
[] :: * -> *
(->) :: * -> * -> *
Kind signatures
The kind system is a part of the Haskell Standard, but as defined, kinds are completely hidden from the surface and do not occur explicitly in the language.
However, you can enable explicit kind signatures via the KindSignatures #Language_Extensions .
code:kindsignatures.hs
data WrappedInt (f :: * -> *) = Wrap (f Int :: *)
class Functor (f :: * -> *) where
fmap :: (a -> b) -> f a -> f b
Kind annotations are possible for arguments and type terms, but there’s no separate “kind signature” declaration as there is for functions and constants.
The kind Contstraint
With the ConstraintKinds #Language_Extensions , we are allowed to talk about the kind Constraint of class constraints explicitly:
code:constraint.hs
Eq :: * -> Constraint
Show :: * -> Constraint
Functor :: (* -> *) -> Constraint
Applicative :: (* -> *) -> Constraint
Monad :: (* -> *) -> Constraint
#Type_level_programming