Kind (type theory): Difference between revisions
Added Scala as a language with a kinding system, plus a reference to a paper describing Scala's use of them |
|||
Line 1: | Line 1: | ||
In [[computer science]] and [[type theory]], a '''kind''' is a "type of a type". Kinds appear, either explicitly or implicitly, in certain languages with complex type systems, such as [[Haskell (programming language)|Haskell]]. In the same way that [[data type|types]] are used to describe the available operations on a value, kinds are used to describe the available operations on a type. |
In [[computer science]] and [[type theory]], a '''kind''' is a "type of a type". Kinds appear, either explicitly or implicitly, in certain languages with complex type systems, such as [[Haskell (programming language)|Haskell]] and [[Scala (programming language)|Scala]] <ref name="higherkinds">[http://www.cs.kuleuven.be/~adriaan/files/higher.pdf Towards Equal Rights for Higher Kinded Types]</ref>. In the same way that [[data type|types]] are used to describe the available operations on a value, kinds are used to describe the available operations on a type. |
||
Kind systems are often far simpler than [[type system]]s. They are used primarily to distinguish between "[[data type]]s" and "type constructors". |
Kind systems are often far simpler than [[type system]]s. They are used primarily to distinguish between "[[data type]]s" and "type constructors". |
Revision as of 03:58, 10 January 2009
In computer science and type theory, a kind is a "type of a type". Kinds appear, either explicitly or implicitly, in certain languages with complex type systems, such as Haskell and Scala [1]. In the same way that types are used to describe the available operations on a value, kinds are used to describe the available operations on a type.
Kind systems are often far simpler than type systems. They are used primarily to distinguish between "data types" and "type constructors".
Kinds in Haskell
Haskell's kind system[2] has just two rules:
- is the kind of all "data types".
- is the kind of a "type constructor", which takes a type of kind and produces a type of kind .
A "data type" (or "inhabited type") is a type which has values. For instance, 4
is a value of type Int
, while [1, 2, 3]
is a value of type [Int]
(list of Ints). Therefore, Int
and [Int]
are both types of kind .
A "type constructor" takes one or more type arguments, and produces a data type when enough arguments are supplied. 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 . Because Int
has kind , applying it to []
results in [Int]
, of kind .
In general, if a type has kind , and type has kind , then the result of the type application has kind .
The way kinds govern types is analogous to the way types govern values. If a function value has type (that is, it is a function which accepts a and produces a ), and value has type , then the result of the function application has type .