... | @@ -38,7 +38,7 @@ The single data type `Type` is used to represent |
... | @@ -38,7 +38,7 @@ The single data type `Type` is used to represent |
|
|
|
|
|
GHC's use of [coercions and equality constraints](commentary/compiler/fc) is important enough to deserve its own page.
|
|
GHC's use of [coercions and equality constraints](commentary/compiler/fc) is important enough to deserve its own page.
|
|
|
|
|
|
## The representation of {{Type}}
|
|
## The representation of `Type`
|
|
|
|
|
|
|
|
|
|
Here, then is the representation of types (see [compiler/types/TypeRep.lhs](/trac/ghc/browser/ghc/compiler/types/TypeRep.lhs) for more details):
|
|
Here, then is the representation of types (see [compiler/types/TypeRep.lhs](/trac/ghc/browser/ghc/compiler/types/TypeRep.lhs) for more details):
|
... | @@ -109,4 +109,73 @@ Type variables range over both *types* (possibly of higher kind) or *coercions*. |
... | @@ -109,4 +109,73 @@ Type variables range over both *types* (possibly of higher kind) or *coercions*. |
|
|
|
|
|
```wiki
|
|
```wiki
|
|
isCoercionVar :: TyVar -> Bool
|
|
isCoercionVar :: TyVar -> Bool
|
|
``` |
|
```
|
|
\ No newline at end of file |
|
|
|
|
|
## Classifying types
|
|
|
|
|
|
|
|
|
|
|
|
GHC uses the following nomenclature for types:
|
|
|
|
|
|
|
|
<table><tr><th>**Unboxed**</th>
|
|
|
|
<td>A type is unboxed iff its representation is other than a pointer. Unboxed types are also unlifted.
|
|
|
|
</td></tr></table>
|
|
|
|
|
|
|
|
<table><tr><th>**Lifted**</th>
|
|
|
|
<td>A type is lifted iff it has bottom as an element. Closures always have lifted types: i.e. any let-bound identifier in Core must have a lifted type. Operationally, a lifted object is one that can be entered. Only lifted types may be unified with a type variable.
|
|
|
|
</td></tr></table>
|
|
|
|
|
|
|
|
<table><tr><th>**Data**</th>
|
|
|
|
<td>A type declared with **`data`**. Also boxed tuples.
|
|
|
|
</td></tr></table>
|
|
|
|
|
|
|
|
<table><tr><th>**Algebraic**</th>
|
|
|
|
<td>An algebraic data type is a data type with one or more constructors, whether declared with `data` or `newtype`. An algebraic type is one that can be deconstructed with a case expression. "Algebraic" is **NOT** the same as "lifted", because unboxed tuples count as "algebraic".
|
|
|
|
</td></tr></table>
|
|
|
|
|
|
|
|
<table><tr><th>**Primitive**</th>
|
|
|
|
<td>a type is primitive iff it is a built-in type that can't be expressed in Haskell.
|
|
|
|
|
|
|
|
Currently, all primitive types are unlifted, but that's not necessarily the case. (E.g. Int could be primitive.)
|
|
|
|
</td></tr></table>
|
|
|
|
|
|
|
|
>
|
|
|
|
> Some primitive types are unboxed, such as Int\#, whereas some are boxed but unlifted (such as ByteArray\#). The only primitive types that we classify as algebraic are the unboxed tuples.
|
|
|
|
|
|
|
|
|
|
|
|
Examples of type classifications:
|
|
|
|
|
|
|
|
<table><tr><th></th>
|
|
|
|
<th>**Primitive**</th>
|
|
|
|
<th>**Boxed**</th>
|
|
|
|
<th>**Lifted**</th>
|
|
|
|
<th>**Algebraic**</th></tr>
|
|
|
|
<tr><th>`Int#`</th>
|
|
|
|
<th> Yes </th>
|
|
|
|
<th> No </th>
|
|
|
|
<th> No </th>
|
|
|
|
<th> No
|
|
|
|
</th></tr>
|
|
|
|
<tr><th>`ByteArray#`</th>
|
|
|
|
<th> Yes </th>
|
|
|
|
<th> Yes </th>
|
|
|
|
<th> No </th>
|
|
|
|
<th> No
|
|
|
|
</th></tr>
|
|
|
|
<tr><th>`(# a, b #)`</th>
|
|
|
|
<th> Yes </th>
|
|
|
|
<th> No </th>
|
|
|
|
<th> No </th>
|
|
|
|
<th> Yes
|
|
|
|
</th></tr>
|
|
|
|
<tr><th>`( a, b )`</th>
|
|
|
|
<th> No </th>
|
|
|
|
<th> Yes </th>
|
|
|
|
<th> Yes </th>
|
|
|
|
<th> Yes
|
|
|
|
</th></tr>
|
|
|
|
<tr><th>`[a]`</th>
|
|
|
|
<th> No </th>
|
|
|
|
<th> Yes </th>
|
|
|
|
<th> Yes </th>
|
|
|
|
<th> Yes
|
|
|
|
</th></tr></table> |
|
|
|
\ No newline at end of file |