Version 3 (modified by 11 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.

`forall`

s in the second argument of `->`

could be permitted as a convenience, but they are equivalent to `forall`

s further out.
`forall`

s 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.

## References

- Arbitrary-rank polymorphism in the GHC User's Guide.
- Practical type inference for arbitrary-rank types, Simon Peyton Jones, Dimitrios Vytiniotis, Stephanie Weirich and Mark Shields, July 2005.
- Rank2Types are a special case

## Pros

- More convenient than encodings using PolymorphicComponents

## Cons

- 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.