diff options
author | Simon Peyton Jones <simonpj@microsoft.com> | 2020-12-22 13:28:37 +0000 |
---|---|---|
committer | Marge Bot <ben+marge-bot@smart-cactus.org> | 2020-12-23 10:23:51 -0500 |
commit | 79d41f93a98d1a331f7c2dfee55da9c1fea01380 (patch) | |
tree | f6e244e33d01bee72e64f1e1f41375af52acf17b | |
parent | cce1514ae7e8b3174bcd66f98247db3ad7928ebc (diff) | |
download | haskell-79d41f93a98d1a331f7c2dfee55da9c1fea01380.tar.gz |
Document scoping of named wildcard type variables
See `Note [Scoping of named wildcards]` in GHC.Hs.Type
This lack of documentation came up in #19051.
-rw-r--r-- | docs/users_guide/exts/partial_type_signatures.rst | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/docs/users_guide/exts/partial_type_signatures.rst b/docs/users_guide/exts/partial_type_signatures.rst index 4d523dd80f..a6a4f73a6a 100644 --- a/docs/users_guide/exts/partial_type_signatures.rst +++ b/docs/users_guide/exts/partial_type_signatures.rst @@ -151,6 +151,20 @@ Besides an extra-constraints wildcard (see :ref:`extra-constraints-wildcard`), only named wildcards can occur in the constraints, e.g. the ``_x`` in ``Show _x``. +When :extension:`ScopedTypeVariables` is on, the named wildcards of a +function signature scope over the function body just like +explicitly-forall'd type variables (:ref:`scoped-type-variables`), +even though there is no explicit forall. For example: :: + + f :: _a -> _a + f x = let g :: _a -> _a + g = ... + in ... + +Here the named wildcard ``_a`` scopes over the body of ``f``, thereby +binding the occurrences of ``_a`` in the signature of ``g``. All +four occurrences stand for the same type. + Named wildcards *should not be confused with type variables*. Even though syntactically similar, named wildcards can unify with monotypes as well as be generalised over (and behave as type variables). |