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

GHC ghc-devs at haskell.org
Sun May 22 19:31:54 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:                    |
-------------------------------------+-------------------------------------
Changes (by RyanGlScott):

 * owner:   => RyanGlScott


Comment:

 I'm working on this now.

 Before I get too far, I wanted to ask about a potential design choice for
 this feature. I like just about everything in comment:19 except for one
 thing: I don't think we should introduce pragmas for explicitly requesting
 a "deriving strategy" (the phrase I coined to describe this), if only
 because it unnecessarily changes the syntax. I think we could just as
 effectively use type synonyms to denote which deriving strategy you want:

 {{{#!hs
 -- | Derive a type class instance using GHC's default behavior.
 type Builtin (a :: k) = a

 -- | Derive a type class instance by generating an instance with no
 -- implementations for any class methods or associated types. This
 requires the
 -- @-XDeriveAnyClass@ extension.
 type DAC (a :: k) = a

 -- | Derive a type class instance for a newtype by using the underlying
 type's
 -- instance for that class. This requires the
 @-XGeneralizedNewtypeDeriving@
 -- extension.
 type GND (a :: k) = a
 }}}

 Then we can specify a deriving strategy (for both `deriving` clauses and
 standalone `deriving`) without any new syntax:

 {{{#!hs
 data Foo a = Foo a
   deriving ( Builtin Show
             , DAC (Bar Int)
             )

 deriving instance Quux a => GND (Quux (Foo a))
 }}}

 Then GHC simply has to check for the presence of one of these magical
 types before deciding which deriving mechanism to actually use. Does this
 sound agreeable?

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


More information about the ghc-tickets mailing list