Note [HsType binders]
The system for recording type and kind-variable binders in HsTypes
is a bit complicated. Here's how it works.
* In a HsType,
HsForAllTy represents an /explicit, user-written/ 'forall' that
is nested within another HsType
e.g. forall a b. {...} or
forall a b -> {...}
Note that top-level 'forall's are represented with a
different AST form. See the description of HsOuterTyVarBndrs
below.
HsQualTy represents an /explicit, user-written/ context
e.g. (Eq a, Show a) => ...
The context can be empty if that's what the user wrote
These constructors represent what the user wrote, no more
and no less.
* The ForAllTelescope field of HsForAllTy represents whether a forall is
invisible (e.g., forall a b. {...}, with a dot) or visible
(e.g., forall a b -> {...}, with an arrow).
* HsTyVarBndr describes a quantified type variable written by the
user. For example
f :: forall a (b :: *). blah
here 'a' and '(b::*)' are each a HsTyVarBndr. A HsForAllTy has
a list of LHsTyVarBndrs.
* HsOuterTyVarBndrs is used to represent the outermost quantified type
variables in a type that obeys the forall-or-nothing rule. An
HsOuterTyVarBndrs can be one of the following:
HsOuterImplicit (implicit quantification, added by renamer)
f :: a -> a -- Desugars to f :: forall {a}. a -> a
HsOuterExplicit (explicit user quantification):
f :: forall a. a -> a
See Note [forall-or-nothing rule].
* An HsSigType is an LHsType with an accompanying HsOuterTyVarBndrs that
represents the presence (or absence) of its outermost 'forall'.
See Note [Representing type signatures].
* HsWildCardBndrs is a wrapper that binds the wildcard variables
of the wrapped thing. It is filled in by the renamer
f :: _a -> _
The enclosing HsWildCardBndrs binds the wildcards _a and _.
* HsSigPatType describes types that appear in pattern signatures and
the signatures of term-level binders in RULES. Like
HsWildCardBndrs/HsOuterTyVarBndrs, they track the names of wildcard
variables and implicitly bound type variables. Unlike
HsOuterTyVarBndrs, however, HsSigPatTypes do not obey the
forall-or-nothing rule. See Note [Pattern signature binders and scoping].
* The explicit presence of these wrappers specifies, in the HsSyn,
exactly where implicit quantification is allowed, and where
wildcards are allowed.
* LHsQTyVars is used in data/class declarations, where the user gives
explicit *type* variable bindings, but we need to implicitly bind
*kind* variables. For example
class C (a :: k -> *) where ...
The 'k' is implicitly bound in the hsq_tvs field of LHsQTyVars References 3
- forall-or-nothing rule Language.Haskell.Syntax.Type
- Pattern signature binders and scoping Language.Haskell.Syntax.Type
- Representing type signatures Language.Haskell.Syntax.Type
Referenced by 6
- Language.Haskell.Syntax.Type call site ×6