Kind polymorphism

Type families gives us functions at the type-level (through type functions). Analogously, the Polykinds language extension gives us polymorphism at the type-level.

Kind polymorphism (Giving Haskell a Promotion, by Yorgey et al in 2012) allows us to describe more generic data and functions. For example, when designing a type-class, the need may arise to cater for various kind-orders. Consider the multiple Typeable classes for multiple arities as an example:

class Typeable (a :: * ) where
  typeOf :: a -> TypeRep

class Typeable1 (a :: * -> *) where
  typeOf1 :: forall b. a b -> TypeRep

The same goes for the Generic type-class we encountered earlier: we need to define different type-classes for different kind arities.

To explore kind polymorphism, ...

Get Haskell Design Patterns now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.