[GHC] #10598: DeriveAnyClass and GND don't work well together

GHC ghc-devs at haskell.org
Fri Aug 5 13:29:33 UTC 2016


#10598: DeriveAnyClass and GND don't work well together
-------------------------------------+-------------------------------------
        Reporter:  osa1              |                Owner:  RyanGlScott
            Type:  bug               |               Status:  patch
        Priority:  normal            |            Milestone:  8.2.1
       Component:  Compiler          |              Version:  7.11
      Resolution:                    |             Keywords:  Generics
Operating System:  Unknown/Multiple  |         Architecture:
                                     |  Unknown/Multiple
 Type of failure:  None/Unknown      |            Test Case:
      Blocked By:                    |             Blocking:
 Related Tickets:                    |  Differential Rev(s):  Phab:D2280
       Wiki Page:                    |
-------------------------------------+-------------------------------------

Comment (by RyanGlScott):

 I like your algorithm much better, since it has no jumps/gotos. I've
 updated the wiki page to use it. I've also updated the table to use more
 accurate labels. Thank you for the peer editing!

 As for your other questions:

 > Surely with the role situation, it will always fail even if you ask for
 it? Also, I noticed in the code you linked a comment that it wouldn't be
 equivalent in any case for law-breaking `Applicatives`.

 Yes, it will always fail. But that's the point of
 `-XDerivingStrategies`—by explicitly using the `newtype` keyword, you take
 on the burden of ensuring that your typeclass can actually be derived, and
 you must accept the consequences if you try something which won't work.

 > My point in the rest of that comment was that even adding that phrase
 isn't ''enough'', because the wording and fallthrough still implies that
 anyclass would be used in this case:
 >
 > {{{#!hs
 > {-# LANGUAGE GeneralizedNewtypeDeriving, DeriveAnyClass #-}
 >
 > newtype F x = F ([x], Maybe x) deriving Functor
 > }}}
 >
 > In fact, even assuming anyclass is not used, that example is a bit
 worrisome: What exactly does GHC do in this case? Does it succeed in
 deriving `Functor`? (I assume No.) If it fails, does it give an error
 message that doesn't confuse the user about why it fails?

 That is a very good point, and one which your refactored table takes into
 account, so now the table reflects the reality that `-XDeriveAnyClass`
 does //not// fall through in this case. In case you're curious, here's the
 error message that GHC gives for that example:

 {{{
     • Can't make a derived instance of ‘Functor F’
         (even with cunning GeneralizedNewtypeDeriving):
         You need DeriveFunctor to derive an instance for this class
     • In the newtype declaration for ‘F’
 }}}


 That seems like a sensible error to me. I'll add a test case for this in
 Phab:2280 to be safe.

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


More information about the ghc-tickets mailing list