views:

254

answers:

3

Polymorphic kinds are an extension to Haskell's type system, supported by UHC, allowing

data A x y = A (y x)

to be typed (kinded?) as a -> (a -> *) -> *. What are they useful for?

+1  A: 

They are useful for defining functions that operate over data constructors with arbitrary arity, of course!

A concrete example could be a function that, given a data constructor with arbitrary arity, returns a new data constructor that wraps the given constructor in Some().

Jordan Lewis
Can you give an example?
Jason Dusek
+5  A: 

One possible usage example can be using conal's TypeCompose for composing monad transformers in point-free style.

type MyT = StateT Foo :. MaybeT :. ContT Bar

(just as an example, I have no idea what one's going to do with those foos and bars..)

Instead of:

type MyT m = StateT Foo (MaybeT (ContT Bar m))

(this would have the same result apart from newtype-wrappers)

Currently you'll need to duplicate the combinators code for different kinds, and this extension abolishes the repetition and allows using one piece of code to rule them all.

yairchu
+3  A: 

Adding Polymorphic Kinds to GHC

The background to this question would be the motivation in general for a more expressive kind system.

That is, the overall reason to add polymorphic kinds to Haskell is to improve the experience of type level programming. Currently type level programming in Haskell proceeds in a essentially untyped "kind" level. A richer kind language will make type level programming in Haskell, in general, easier.

A more concrete example would be to remove the (dynamic) Typeable constraint from generics of the SYB style (citation), as well as improving overall support for higher-kinded generic programming..

Don Stewart