[GHC] #12814: Should GND infer an instance context when deriving method-free classes?

GHC ghc-devs at haskell.org
Tue Nov 8 15:53:03 UTC 2016


#12814: Should GND infer an instance context when deriving method-free classes?
-------------------------------------+-------------------------------------
        Reporter:  RyanGlScott       |                Owner:
            Type:  bug               |               Status:  new
        Priority:  normal            |            Milestone:  8.2.1
       Component:  Compiler (Type    |              Version:  8.0.1
  checker)                           |
      Resolution:                    |             Keywords:
Operating System:  Unknown/Multiple  |         Architecture:
                                     |  Unknown/Multiple
 Type of failure:  None/Unknown      |            Test Case:
      Blocked By:                    |             Blocking:
 Related Tickets:  #11369, #12810    |  Differential Rev(s):
       Wiki Page:                    |
-------------------------------------+-------------------------------------

Comment (by RyanGlScott):

 Replying to [comment:5 goldfire]:
 > Can't we just type-check the generated code and then posit whatever
 constraints are necessary for that code to be accepted? That's what we do
 for `stock` instances, no?

 Currently, no. The code for this is
 [http://git.haskell.org/ghc.git/blob/2e8463b232054b788b73e6551947a9434aa76009:/compiler/typecheck/TcDerivInfer.hs#l46
 inferConstraints] in `TcDerivInfer`. For stock deriving, it walks over
 each field of each constructor for a datatype, puts the class constraint
 on the field's type, and then simplifies. So `data Foo a b = Foo a Int
 deriving Show` becomes `(Show a, Show Int)` becomes `Show a`.

 As for why this is done this way, I'm not sure, but I do know that GHC
 figures out the instance context //before// ever generating the class
 method implementations (possibly for typechecking purposes).

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


More information about the ghc-tickets mailing list