diff options
author | Ryan Scott <ryan.gl.scott@gmail.com> | 2019-04-30 11:28:41 -0400 |
---|---|---|
committer | Ömer Sinan Ağacan <omeragacan@gmail.com> | 2019-05-03 21:54:50 +0300 |
commit | cc495d5777c01ef62129df15caacf87b0e430c6b (patch) | |
tree | 98367d77415752a0b21e0bcb9a5cacd233de32c5 /docs | |
parent | 87bc954ab65aaf08b4f59cf46bd2916acd69ea73 (diff) | |
download | haskell-cc495d5777c01ef62129df15caacf87b0e430c6b.tar.gz |
Make equality constraints in kinds invisible
Issues #12102 and #15872 revealed something strange about the way GHC
handles equality constraints in kinds: it treats them as _visible_
arguments! This causes a litany of strange effects, from strange
error messages
(https://gitlab.haskell.org/ghc/ghc/issues/12102#note_169035)
to bizarre `Eq#`-related things leaking through to GHCi output, even
without any special flags enabled.
This patch is an attempt to contain some of this strangeness.
In particular:
* In `TcHsType.etaExpandAlgTyCon`, we propagate through the
`AnonArgFlag`s of any `Anon` binders. Previously, we were always
hard-coding them to `VisArg`, which meant that invisible binders
(like those whose kinds were equality constraint) would mistakenly
get flagged as visible.
* In `ToIface.toIfaceAppArgsX`, we previously assumed that the
argument to a `FunTy` always corresponding to a `Required`
argument. We now dispatch on the `FunTy`'s `AnonArgFlag` and map
`VisArg` to `Required` and `InvisArg` to `Inferred`. As a
consequence, the iface pretty-printer correctly recognizes that
equality coercions are inferred arguments, and as a result,
only displays them in `-fprint-explicit-kinds` is enabled.
* Speaking of iface pretty-printing, `Anon InvisArg` binders were
previously being pretty-printed like `T (a :: b ~ c)`, as if they
were required. This seemed inconsistent with other invisible
arguments (that are printed like `T @{d}`), so I decided to switch
this to `T @{a :: b ~ c}`.
Along the way, I also cleaned up a minor inaccuracy in the users'
guide section for constraints in kinds that was spotted in
https://gitlab.haskell.org/ghc/ghc/issues/12102#note_136220.
Fixes #12102 and #15872.
Diffstat (limited to 'docs')
-rw-r--r-- | docs/users_guide/glasgow_exts.rst | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/docs/users_guide/glasgow_exts.rst b/docs/users_guide/glasgow_exts.rst index 781a10691e..c86f30d00b 100644 --- a/docs/users_guide/glasgow_exts.rst +++ b/docs/users_guide/glasgow_exts.rst @@ -9395,7 +9395,8 @@ Here is an example of a constrained kind: :: The declarations above are accepted. However, if we add ``MkOther :: T Int``, we get an error that the equality constraint is not satisfied; ``Int`` is not a type literal. Note that explicitly quantifying with ``forall a`` is -not necessary here. +necessary in order for ``T`` to typecheck +(see :ref:`complete-kind-signatures`). The kind ``Type`` ----------------- @@ -10351,13 +10352,13 @@ function that can *never* be called, such as this one: :: f :: (Int ~ Bool) => a -> a Sometimes :extension:`AllowAmbiguousTypes` does not mix well with :extension:`RankNTypes`. -For example: :: +For example: :: foo :: forall r. (forall i. (KnownNat i) => r) -> r foo f = f @1 boo :: forall j. (KnownNat j) => Int boo = .... - + h :: Int h = foo boo @@ -10367,7 +10368,7 @@ the type variables `j` and `i`. Unlike the previous examples, it is not currently possible to resolve the ambiguity manually by using :extension:`TypeApplications`. - + .. note:: *A historical note.* GHC used to impose some more restrictive and less principled conditions on type signatures. For type |