[GHC] #11008: Difficulties around inferring exotic contexts (was: GND with Type Families)
GHC
ghc-devs at haskell.org
Fri Oct 23 14:22:35 UTC 2015
#11008: Difficulties around inferring exotic contexts
-------------------------------------+-------------------------------------
Reporter: crockeea | Owner:
Type: bug | Status: new
Priority: normal | Milestone:
Component: Compiler | Version: 7.10.2
Resolution: | Keywords:
Operating System: Unknown/Multiple | Architecture:
| Unknown/Multiple
Type of failure: None/Unknown | Test Case:
Blocked By: | Blocking:
Related Tickets: | Differential Rev(s):
Wiki Page: |
-------------------------------------+-------------------------------------
Comment (by goldfire):
This is by design. GHC refuses to infer so-called exotic contexts,
believing that sufficiently exotic contexts should be written by the user.
This behavior is independent of whether GND or other `deriving` features
are used. Here is an extreme example:
{{{
data X a b = MkX (a -> b) deriving Eq
}}}
This fails, complaining about a missing `Eq (a -> b)` instance. (My choice
of `data` vs. `newtype` is utterly irrelevant here.) But I can write this:
{{{
deriving instance Eq (a -> b) => Eq (X a b)
}}}
Should GHC infer the context automatically here? I think not -- it masks a
deeper problem.
Now, returning to the original post: should GHC infer that context? It
looks just like the example I just gave, where the context requires an
`Eq` constraint on some other type constructor.
It all boils down to yet another knob we can turn in the internals of GHC.
It's a very easy knob to turn, with no interactions throughout the code.
See the relevant function
[https://github.com/ghc/ghc/blob/8f5ad1a009eddd05447ff8057792b4d03983cd35/compiler/typecheck/TcValidity.hs#L949
here], with a Note directly above.
If you can suggest a better setting for the knob, go right ahead. :)
Regardless, we should document this in the manual somewhere, as it is all
user-facing.
--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/11008#comment:1>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
More information about the ghc-tickets
mailing list