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

GHC ghc-devs at haskell.org
Mon Nov 7 22:18:44 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:2 goldfire]:
 > Frankly, I was surprised that GND assumes any class constraint at all.
 Why should it be different than other forms of `deriving`? Just infer the
 class constraint based on the constraints that arise when type-checking
 the generated definition.

 I'm not sure how the thing you're imagining is different from what
 actually happens. GND must infer a constraint (applied to the
 representation type for the newtype) in order to typecheck any calls to
 `coerce` that GND generates. This is quite similar to stock deriving. For
 example, in:

 {{{#!hs
 data Foo a b = Foo b
   deriving Show
 }}}

 You must infer `Show b` in order to typecheck the generated `showsPrec`
 function.

 The only difference in this scenario is that there are no stock derivable
 classes without methods, but with GND, such a thing is possible. So it's
 quite a different beast.

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


More information about the ghc-tickets mailing list