[commit: ghc] master: More clarification in docs for implicit quantification (454585c)
git at git.haskell.org
git at git.haskell.org
Fri Mar 25 10:40:28 UTC 2016
Repository : ssh://git@git.haskell.org/ghc
On branch : master
Link : http://ghc.haskell.org/trac/ghc/changeset/454585c6802f0de4d23f9f16de591596533503b7/ghc
>---------------------------------------------------------------
commit 454585c6802f0de4d23f9f16de591596533503b7
Author: Simon Peyton Jones <simonpj at microsoft.com>
Date: Fri Mar 25 10:41:57 2016 +0000
More clarification in docs for implicit quantification
This is a follow-up patch to the previous one for #11726.
It turns out that I'd missed the point of the ticket; this
patch addresses it.
>---------------------------------------------------------------
454585c6802f0de4d23f9f16de591596533503b7
docs/users_guide/glasgow_exts.rst | 14 +++++++++++++-
1 file changed, 13 insertions(+), 1 deletion(-)
diff --git a/docs/users_guide/glasgow_exts.rst b/docs/users_guide/glasgow_exts.rst
index 7ecc929..0735cfc 100644
--- a/docs/users_guide/glasgow_exts.rst
+++ b/docs/users_guide/glasgow_exts.rst
@@ -9148,7 +9148,7 @@ argument of constructor ``T1`` and that tells GHC all it needs to know.
Implicit quantification
-----------------------
-GHC performs implicit quantification as follows. At the top level
+GHC performs implicit quantification as follows. At the outermost level
(only) of user-written types, if and only if there is no explicit
``forall``, GHC finds all the type variables mentioned in the type that
are not already in scope, and universally quantifies them. For example,
@@ -9188,6 +9188,18 @@ If you want the latter type, you can write
your ``forall``\s explicitly. Indeed, doing so is strongly advised for
rank-2 types.
+Sometimes there *is* no "outermost level", in which case no
+implicit quanification happens: ::
+
+ data PackMap a b s t = PackMap (Monad f => (a -> f b) -> s -> f t)
+
+This is rejected because there is no "outermost level" for the types on the RHS
+(it would obviously be terrible to add extra parameters to ``PackMap``),
+so no implicit quantificaiton happens, and the declaration is rejected
+(with "``f`` is out of scope"). Solution: use an explicit ``forall``: ::
+
+ data PackMap a b s t = PackMap (forall f. Monad f => (a -> f b) -> s -> f t)
+
.. _impredicative-polymorphism:
Impredicative polymorphism
More information about the ghc-commits
mailing list