Higher-kinded polymorphism

Type­classes with one type parameter are of kind (* -> *), for example:

  class Show  a :: * -> *
  class Maybe a :: * -> *

If we declare an instance of Show, then the type­class parameters in the kind signatures need to be aligned, for example, consider:

  instance (Show a) => Show (Maybe a) where ...

In order to match the kind of a :: * in Show a, we use Maybe' b instead of Maybe:

  Maybe' b :: *
  -- instead of
  Maybe :: (* -> *)

The Monad type-class is of a higher-order than Show and Maybe:

 class Monad m :: (* -> *) -> *
 --               m     -> Monad m

The Show type-class is parameterized over type a :: *; whereas Monad is parameterized over the type constructor m :: * -> *. This can seem like a natural and unsurprising generalization for type-classes, but was in fact an exciting leap forward for Haskell, as described in Hudak et al's History of Haskell:

"The first major, unanticipated development in the type-class story came when Mark Jones suggested parameterizing a class over a type constructor instead of over a type...

"Jones's paper appeared in 1993, the same year that monads became popular for I/O. The fact that type classes so directly supported monads made monads far more accessible and popular; and dually, the usefulness of monadic I/O ensured the adoption of higher-kinded polymorphism."

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset