[GHC] #15052: DeriveAnyClass instances may skip TypeError constraints

GHC ghc-devs at haskell.org
Wed Apr 18 15:24:21 UTC 2018


#15052: DeriveAnyClass instances may skip TypeError constraints
-------------------------------------+-------------------------------------
        Reporter:  jcpetruzza        |                Owner:  (none)
            Type:  bug               |               Status:  new
        Priority:  normal            |            Milestone:  8.6.1
       Component:  Compiler          |              Version:  8.2.2
      Resolution:                    |             Keywords:
                                     |  CustomTypeErrors
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 RyanGlScott):

 Here is the difference between these two programs. In the first one:

 {{{#!hs
 data TS = TSL | TSR  deriving (Gen.Generic, C)
 }}}

 You are requesting that GHC come up with the `???` in the following
 instance:

 {{{#!hs
 instance ??? => C TS
 }}}

 Because `C` has a superclass constraint, `TypeError (...)`, it infers that
 for `???`. If you had picked different superclass constraints for `C`,
 such as `class (Eq a, Show a) => C a`, then GHC would have inferred `(Eq
 a, Show a)` for `???`.

 In the second example, you are putting the task of coming up with the
 context in your own hands. You have boldly declared that the instance
 context should be `()`! As a result, GHC tries to unify `TypeError (...)`
 with `()`, which causes the type error to trigger. Boom.

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


More information about the ghc-tickets mailing list