[GHC] #11008: Difficulties around inferring exotic contexts

GHC ghc-devs at haskell.org
Fri Oct 23 18:40:59 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):

 Replying to [comment:2 crockeea]:
 > With the deriving clause, which instance does GHC try to create?
 >
 >   1. `instance (Eq (Foo r)) => Eq (Bar r)`
 >   2. `instance (C (F r), Eq r) => Eq (Bar r)`
 >

 Option 1. But it then tries to simplify the constraint, finding the
 minimal set of constraints that imply `Eq (Foo r)`. Here, minimal does not
 mean smallest, but instead minimal in a logical sense -- as in, the
 minimum set of assumptions that proves the desired constraint. So, option
 1 very quickly becomes option 2.

 Note that if we didn't try to simplify, then you'd end up with constraints
 like `Eq (Maybe a)` a lot, and these would be rejected.

 > In either case, since I *have* a matching `Eq` instance for `Foo`, GHC
 should assume that I knew what I was doing when I wrote it, and just use
 it. This doesn't change the behavior when no matching instance is found,
 like in your example.

 But you have no matching instance for `C (F r)`. So I'm not sure how GHC
 should recognize the difference.

--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/11008#comment:3>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler


More information about the ghc-tickets mailing list