Version 3 (modified by ross@…, 12 years ago) (diff)

Rank-N Types

See ExtensionDescriptionHowto for information on how to write these extension descriptions. Please add any new extensions to the list of HaskellExtensions.

Brief Explanation

Haskell 98 provides only rank-1 types: universal quantification is over the whole type expressions, and is implicit, e.g.

const :: a -> b -> a

Rank-2 types may have polymorphic arguments, marked by forall, e.g.

plus :: (forall a. a -> a) -> (forall a. a -> a) -> b -> b

Rank-3 types may have arguments of rank-2 type, e.g.

f3 :: ((forall a. a->a) -> Int) -> Bool -> Bool

and so on to arbitrary depth.

foralls in the second argument of -> could be permitted as a convenience, but they are equivalent to foralls further out. foralls are not permitted inside arguments of other type constructors.

The GHC User's Guide has some vague remarks about how type signature information is used. Perhaps someone could elaborate.




  • More complex than Rank2Types, which cover the most common cases (and can encode the rest, though clumsily).
  • No clear programmer-level description of the restrictions that apply.