Frequent Links
Kind (type theory)
In the area of mathematical logic and computer science known as type theory, a kind is the type of a type constructor or, less commonly, the type of a higherorder type operator. A kind system is essentially a simply typed lambda calculus "one level up", endowed with a primitive type, denoted <math>*</math> and called "type", which is the kind of any data type which does not need any type parameters.
A kind is sometimes confusingly described as the "type of a (data) type", but it is actually more of an arity specifier. Syntactically, it is natural to consider polymorphic types to be type constructors, thus nonpolymorphic types to be nullary type constructors. But all nullary constructors, thus all monomorphic types, have the same, simplest kind; namely <math>*</math>.
Since higherorder type operators are uncommon in programming languages, in most programming practice, kinds are used to distinguish between data types and the types of constructors which are used to implement parametric polymorphism. Kinds appear, either explicitly or implicitly, in languages whose type systems account for parametric polymorphism in a programatically accessible way, such as Haskell and Scala.^{[1]}
Examples
 <math>*</math>, pronounced "type", is the kind of all data types seen as nullary type constructors, and also called proper types in this context. This normally includes function types in functional programming languages.
 <math>* \rightarrow *</math> is the kind of a unary type constructor, e.g. of a list type constructor.
 <math>* \rightarrow * \rightarrow *</math> is the kind of a binary type constructor (via currying), e.g. of a pair type constructor, and also that of a function type constructor (not to be confused with the result of its application, which itself is a function type, thus of kind <math>*</math>)
 <math>(* \rightarrow *) \rightarrow *</math> is the kind of a higherorder type operator from unary type constructors to proper types. See Pierce (2002), chapter 32 for an application.
Kinds in Haskell
(Note: Haskell documentation uses the same arrow for both function types and kinds.)
Haskell's kind system^{[2]} has just two rules:^{[vague]}
 <math>*</math>, pronounced "type" is the kind of all data types.
 <math>k_1 \rightarrow k_2</math> is the kind of a unary type constructor, which takes a type of kind <math>k_1</math> and produces a type of kind <math>k_2</math>.
An inhabited type (as proper types are called in Haskell) is a type which has values. For instance, ignoring type classes which complicate the picture, 4
is a value of type Int
, while [1, 2, 3]
is a value of type [Int]
(list of Ints). Therefore, Int
and [Int]
have kind <math>*</math>, but so does any function type, for instance Int > Bool
or even Int > Int > Bool
.
A type constructor takes one or more type arguments, and produces a data type when enough arguments are supplied, i.e. it supports partial application thanks to currying.^{[3]}^{[4]} This is how Haskell achieves parametric types. For instance, the type []
(list) is a type constructor  it takes a single argument to specify the type of the elements of the list. Hence, [Int]
(list of Ints), [Float]
(list of Floats) and even [[Int]]
(list of lists of Ints) are valid applications of the []
type constructor. Therefore, []
is a type of kind <math>* \rightarrow *</math>. Because Int
has kind <math>*</math>, applying it to []
results in [Int]
, of kind <math>*</math>. The 2tuple constructor (,)
has kind <math>* \rightarrow * \rightarrow *</math>, the 3tuple constructor (,,)
has kind <math>* \rightarrow * \rightarrow * \rightarrow *</math> and so on.
Kind inference
Standard Haskell does not allow polymorphic kinds. This is in contrast to parametric polymorphism on types, which is supported in Haskell. For instance, in the following example:
data Tree z = Leaf  Fork (Tree z) (Tree z)
the kind of z
could be anything, including <math>*</math>, but also <math>* \rightarrow *</math> etc. Haskell by default will always infer kinds to be <math>*</math>, unless the type explicitly indicates otherwise (see below). Therefore the type checker will reject the following use of Tree
:
type FunnyTree = Tree []  invalid
because the kind of []
, <math>* \rightarrow *</math> does not match the expected kind for z
, which is always <math>*</math>.
Higherorder type operators are allowed however. For instance:
data App unt z = Z (unt z)
has kind <math>(* \rightarrow *) \rightarrow * \rightarrow *</math>, i.e. unt
is expected to be a unary data constructor, which gets applied to its argument, which must be a type, and returns another type.
GHC has the extension PolyKinds
, which, together with KindSignatures
, allows polymorphic kinds. For example:
data Tree (z :: k) = Leaf  Fork (Tree z) (Tree z) type FunnyTree = Tree []  OK
See also
References
 Pierce, Benjamin (2002). Types and Programming Languages. MIT Press. ISBN 0262162091., chapter 29, "Type Operators and Kinding"
 ^ Generics of a Higher Kind
 ^ Kinds  The Haskell 98 Report
 ^ "Chapter 4 Declarations and Binding". Haskell 2010 Language Report. Retrieved 23 July 2012.
 ^ Miran, Lipovača. "Learn You a Haskell for Great Good!". Making Our Own Types and Typeclasses. Retrieved 23 July 2012.
