GHC/Type system/PolyKinds

From HaskellWiki
< GHC‎ | Type system
Revision as of 04:54, 7 November 2012 by Simonpj (talk | contribs) (New page: = Kind polymorphism = GHC 7.6 introduced kind polymorphism and data kinds for the first time. This page contains notes (currently rather random) about how to use these features. * User ...)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

Kind polymorphism

GHC 7.6 introduced kind polymorphism and data kinds for the first time. This page contains notes (currently rather random) about how to use these features.

Syntactic ambiguity for lists

Suppose Proxy :: forall k. k -> *, and consider

Proxy [Int]
Proxy [Int,Bool]

The former must mean what it always means in Haskell, namely

Proxy * (List Int)

where I'm writing the kind argument explicitly. To be fully clear, I'm writing List for the type constructor for lists (written [] in Haskell), so (List Int) is a type of kind *.

But Proxy [Int,Bool] can only mean Proxy applied to a list of types, thus:

Proxy [*] (Cons * Int (Cont * Bool (Nil *)))

Now we can see that Proxy [Int] is ambiguous. It could also mean

Proxy [*] (Cons * Int (Nil *))

but we choose the normal meaning to avoid screwing up Haskell programs. To get the above form we have to quote the "[", thus

	Proxy '[ Int ]

In short, singleton lists (and indeed the empty list) must be explicitly promoted with a quote, whereas for type-level lists of two or more elements you don't need an explicit promotion quote.