[commit: ghc] ghc-8.0: More clarification in docs for implicit quantification (8c62c66)

git at git.haskell.org git at git.haskell.org
Fri Mar 25 11:14:49 UTC 2016


Repository : ssh://git@git.haskell.org/ghc

On branch  : ghc-8.0
Link       : http://ghc.haskell.org/trac/ghc/changeset/8c62c669467bf7524635e8891201cdf92e6766fd/ghc

>---------------------------------------------------------------

commit 8c62c669467bf7524635e8891201cdf92e6766fd
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.
    
    (cherry picked from commit 454585c6802f0de4d23f9f16de591596533503b7)


>---------------------------------------------------------------

8c62c669467bf7524635e8891201cdf92e6766fd
 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 38106b0..430431f 100644
--- a/docs/users_guide/glasgow_exts.rst
+++ b/docs/users_guide/glasgow_exts.rst
@@ -9127,7 +9127,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,
@@ -9167,6 +9167,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