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

GHC ghc-devs at haskell.org
Wed Jun 8 14:21:20 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):

 oerjan, I greatly appreciate your effort to salvage the current pragma-
 based approach, but
 [https://ghc.haskell.org/trac/ghc/ticket/10598#comment:33 enough]
 [https://phabricator.haskell.org/D2280#65972 GHC]
 [https://phabricator.haskell.org/D2280#67408 devs] have objected to the
 point that I don't think it's worth pursuing anymore.

 It seems that we need (1) some new syntax for demarcating which deriving
 strategy to use, and (2) a new language extension to hide it behind. Here
 is my proposal:

 1. In `deriving` clauses, one can optionally indicate a deriving strategy
 with the following syntax:

    {{{#!hs
    newtype Foo = Foo Bar deriving ( Eq
                                   , Ord <- builtin
                                   , Read <- newtype
                                   , Show <- default
                                   )
    }}}

    And in standalone `deriving` declarations:

    {{{#!hs
    newtype Foo = Foo Int
    deriving instance Eq Foo
    deriving builtin instance Ord Foo
    deriving newtype instance Read Foo
    deriving default instance Show Foo
    }}}

    where `builtin` corresponds to `BUILTIN`, `newtype` corresponds to
 `GND`, and `default` corresponds to `DAC` in my pragma-based proposal. I'm
 not terribly attached to these names, so if you have better suggestions,
 I'm all ears.

    Importantly, I think we need some way to separate the derived type from
 the strategy in a `deriving` clause, or parsing it will be a nightmare for
 the reasons I laid out in
 [https://ghc.haskell.org/trac/ghc/ticket/10598#comment:34 this comment].
 Standalone deriving declarations won't be as tricky since we can just put
 the strategy between `deriving` and `instance` without too much trouble,
 although we could also require this for consistency:

    {{{#!hs
    deriving instance Eq Foo
    deriving instance Ord Foo <- builtin
    deriving instance Read Foo <- newtype
    deriving instance Show Foo <- default
    }}}

    The choice of `<-` as a delimeter is also completely arbitrary. I think
 we'll need //some// kind of non-alphanumeric thing, but I'm not sure
 what's sensible.
 2. Require the use of `{-# LANGUAGE DerivingStrategies #-}` to use this
 feature.

 Comments?

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


More information about the ghc-tickets mailing list