|Version 3 (modified by ross@…, 8 years ago) (diff)|
Rank 2 Types
Functions may have polymorphic arguments, described by explicit type signatures, e.g.
g :: (forall a. a -> a) -> (Bool, Char) g f = (f True, f 'a')
In the definition of the function, polymorphic arguments must be matched, and can only be matched by a variable or wildcard (_) pattern.
When such a function is used, it must be applied to an expression whose generalized type is at least as general as that declared, e.g.
g id g undefined
The more general RankNTypes avoid these restrictions.
PolymorphicComponents are closely related.
- simple type inference
- enables runST and similar devices
- used in cheap deforestation
- can be awkward in comparison with RankNTypes