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

GHC ghc-devs at haskell.org
Mon May 23 10:56:17 UTC 2016


#10598: DeriveAnyClass and GND don't work well together
-------------------------------------+-------------------------------------
        Reporter:  osa1              |                Owner:  RyanGlScott
            Type:  bug               |               Status:  new
        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):
       Wiki Page:                    |
-------------------------------------+-------------------------------------

Comment (by RyanGlScott):

 Let me also address oerjan's proposal to annotate class definitions with
 these pragmas as well to guide which deriving mechanism is chosen.

 I'll admit the idea makes me a bit uncomfortable, since it's not backwards
 compatible. For example, if there's a `class ToJSON` in use with current
 GHCs that becomes annotated with `classs {-# DAC #-} ToJSON`, then the
 following code:

 {{{#!hs
 {-# LANGUAGE GeneralizedNewtypeDeriving #-}

 newtype Foo = Foo Bar deriving ToJSON
 }}}

 would do two different things depending on which GHC is used! If an older
 GHC is used, it'll pick `GeneralizedNewtypeDeriving`, but if a more recent
 GHC is used, it'll pick `DeriveAnyClass`. Not to mention GHC will now
 complain that you need to enable `DeriveAnyClass` for that code to compile
 in the first place, which would be a pretty confusing breakage. This seems
 deeply wrong to me—in my opinion, one should be able to tell from the
 module in which the `deriving` statement is in which mechanism will be
 picked.

 Also, I'm not sure what would happen if you have `class {-# GND #-} Baz`
 and tried to do `data Quux = Quux deriving Baz`. When you explicitly
 annotate a `deriving` statement for a `data` type with `{-# GND #-}`,
 that's an obvious error. But when the pragma is tucked away in a class
 definition (possibly in a far-flung module), it might not be intuitive as
 why that code would error.

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


More information about the ghc-tickets mailing list