|Version 5 (modified by ross@…, 11 years ago) (diff)|
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:
data Tree a = Leaf | Fork (Tree a) (Tree a) type TreeList = Tree  -- illegal
(because Tree has been assigned the kind * -> *).
A more meaningful example is the following attempt to compose monad transformers:
newtype StateT s m a = S (s -> m (a,s)) newtype ReaderT r m a = R (r -> m a) newtype Compose f g m a = C (f (g m) a) type SR s r = Compose (StateT s) (ReaderT r) -- illegal
GHC users have been able to work around this by adding KindAnnotations to the above definition of Compose.
- more liberal kind inference
Listed in order of decreasing need for KindAnnotations (even if you think those are useful in their own right):
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.
Type constructors and classes have polymorphic kinds, inferred over dependency groups. KindAnnotations would never be required.