6.11.1. Explicit universal quantification (forall)


Allow use of the forall keyword in places where universal quantification is implicit.

Haskell type signatures are implicitly quantified. When the language option ExplicitForAll is used, the keyword forall allows us to say exactly what this means. For example:

g :: b -> b

means this:

g :: forall b. (b -> b)

The two are treated identically, except that the latter may bring type variables into scope (see Lexically scoped type variables).

This extension also enables explicit quantification of type and kind variables in Data instance declarations, Type instance declarations, Closed type families, Associated instances, and Rewrite rules.


  • As well in type signatures, you can also use an explicit forall in an instance declaration:

    instance forall a. Eq a => Eq [a] where ...
  • If the -Wunused-foralls flag is enabled, a warning will be emitted when you write a type variable in an explicit forall statement that is otherwise unused. For instance:

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

    would warn about the unused type variable a.