Changes between Version 2 and Version 3 of Commentary/Compiler/Kinds


Ignore:
Timestamp:
Jun 8, 2012 8:34:46 AM (3 years ago)
Author:
simonpj
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • Commentary/Compiler/Kinds

    v2 v3  
    11= Kinds =
    22
    3 Kinds are represented as types:
     3Kinds classify types.  So for example:
     4{{{
     5   Int :: *
     6   Int -> Int :: *
     7   Maybe :: * -> *
     8   Int# :: #
     9   (# Int, Int #) :: #
     10}}}
     11The base kinds are these:
     12 * "`*`" is the kind of boxed values. Things like `Int` and `Maybe Float` have kind `*`.
     13 * "`#`" is the kind of unboxed values. Things like `Int#` have kind `#`.
     14 * With the advent of [wiki:GhcKinds data type promotion and kind polymorphism] we can have a lot more kinds.
     15
     16(Unboxed tuples used to have a distinct kind, but in 2012 we combined unboxed tuples with other unboxed values in a single kind "`#`".)
     17
     18== Representing kinds ==
     19
     20Kinds are represented by the data type `Type` (see [wiki:Commentary/Compiler/TypeType]):
    421{{{
    522type Kind = Type
    623}}}
    7 Basic kinds are now
     24Basic kinds are
    825represented using type constructors, e.g. the kind `*` is represented as
    926{{{
     
    2845=== Kind subtyping ===
    2946
     47There is a small amount of sub-typing in kinds.  Suppose you see `(t1 -> t2)`.  What kind must `t1` and `t2` have?  It could be `*` or `#`.  So we have a single kind `OpenKind`, which is a super-kind of both, with this simple lattice:
     48
    3049[[Image(https://docs.google.com/drawings/pub?id=1M5yBP8iAWTgqdI3oG1UNnYihVlipnvvk2vLInAFxtNM&w=359&h=229)]]
    3150
    3251(You can edit this picture [https://docs.google.com/drawings/d/1M5yBP8iAWTgqdI3oG1UNnYihVlipnvvk2vLInAFxtNM/edit?hl=en_GB here].)
    3352
    34  * "`*`" is the kind of boxed values. Things like `Int` and `Maybe Float` have kind `*`.
    35 
    36  * "`#`" is the kind of unboxed values. Things like `Int#` have kind `#`.
    37 
    38  * "`(#)`" is the kind of unboxed tuples. Things like `(# Int, Int #)` have kind `(#)`.
    39 
    40  * "`ArgKind`" is the kind of things that can appear as arguments to functions.
    41 
    42  * "`OpenKind`" is the kind of things that can appear as results of functions.
     53 * "`OpenKind`" is the kind of things that can appear as argument or result of functions.