6.11.1. Explicit universal quantification (forall)¶
Allow use of the
forallkeyword in places where universal quantification is implicit.
Haskell type signatures are implicitly quantified. When the language
ExplicitForAll is used, the keyword
forall allows us to
say exactly what this means. For example:
g :: b -> b
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
forallin an instance declaration:
instance forall a. Eq a => Eq [a] where ...
-Wunused-forallsflag is enabled, a warning will be emitted when you write a type variable in an explicit
forallstatement that is otherwise unused. For instance:
g :: forall a b. (b -> b)
would warn about the unused type variable a.