|
|
# Kind Inference
|
|
|
|
|
|
|
|
|
## Brief Explanation
|
|
|
|
|
|
|
|
|
|
|
|
Haskell 98 lacks kind polymorphism, and performs kind inference over dependency groups with polymorphic kinds defaulted to `*`. The Report gives the following example of illegal declarations:
|
|
|
|
|
|
|
|
|
```wiki
|
|
|
data Tree a = Leaf | Fork (Tree a) (Tree a)
|
|
|
|
... | ... | @@ -15,8 +18,10 @@ type TreeList = Tree [] -- illegal |
|
|
(because `Tree` has been assigned the kind `* -> *`).
|
|
|
|
|
|
|
|
|
|
|
|
A more meaningful example is the following attempt to compose monad transformers:
|
|
|
|
|
|
|
|
|
```wiki
|
|
|
newtype StateT s m a = S (s -> m (a,s))
|
|
|
|
... | ... | @@ -30,32 +35,38 @@ type SR s r = Compose (StateT s) (ReaderT r) -- illegal |
|
|
|
|
|
GHC users have been able to work around this by adding [KindAnnotations](kind-annotations) to the above definition of `Compose`.
|
|
|
|
|
|
## References
|
|
|
|
|
|
- [ Haskell 98 Kind Inference](http://www.haskell.org/onlinereport/decls.html#kindinference)
|
|
|
## References
|
|
|
|
|
|
## Tickets
|
|
|
|
|
|
<table><tr><th>[\#85](https://gitlab.haskell.org//haskell/prime/issues/85)</th>
|
|
|
<td>more liberal kind inference</td></tr></table>
|
|
|
- [ Haskell 98 Kind Inference](http://www.haskell.org/onlinereport/decls.html#kindinference)
|
|
|
|
|
|
## Alternatives
|
|
|
|
|
|
|
|
|
|
|
|
Listed in order of decreasing need for [KindAnnotations](kind-annotations)
|
|
|
(even if you think those are useful in their own right):
|
|
|
|
|
|
|
|
|
### GHC 6.4
|
|
|
|
|
|
|
|
|
|
|
|
Kind inference is performed across all the `data`, `newtype`, `type` and `class` declarations of a module before defaulting, and so the above examples are accepted.
|
|
|
|
|
|
|
|
|
### Monomorphic kinds, using all available information
|
|
|
|
|
|
|
|
|
|
|
|
Kind inference is performed across the whole module, using all occurrences of type constructors and classes, i.e. the above sources plus instance declarations, type signature declarations and expression type signatures.
|
|
|
|
|
|
|
|
|
### Polymorphic kinds
|
|
|
|
|
|
|
|
|
|
|
|
Type constructors and classes have polymorphic kinds, inferred over dependency groups. [KindAnnotations](kind-annotations) would never be required.
|
|
|
|
|
|
|