[GHC] #15434: DerivingVia (and perhaps even GND) works badly with DeriveGeneric

GHC ghc-devs at haskell.org
Tue Jul 24 17:21:02 UTC 2018


#15434: DerivingVia (and perhaps even GND) works badly with DeriveGeneric
-------------------------------------+-------------------------------------
        Reporter:  konn              |                Owner:  (none)
            Type:  bug               |               Status:  new
        Priority:  normal            |            Milestone:  8.6.1
       Component:  Compiler          |              Version:
      Resolution:                    |             Keywords:  deriving
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):

 * cc: dfeuer (added)


Comment:

 As a counterpoint, I quite dislike the idea of GHC demanding that users
 write instances a certain way. In fact, one of the very reasons I authored
 `DerivingStrategies` in the first place was because one couldn't derive
 classes like `Read` or `Show` by any means except `stock` deriving. True,
 90% of the time, this is what you want, but for the other 10%, having
 explicit control through `DerivingStrategies` is quite handy.

 Replying to [comment:2 konn]:
 > I can't imagine the situation where `Generic` should give the different
 information than its true structure.

 There are folks out there who write `Generic` instances which differ from
 what `stock` deriving would give you for various reasons. One reason is
 that some people like to define data types abstractly and only allow
 creating/matching on values of that data type through pattern synonyms.

 While I don't have any examples of people `newtype`/`via`-deriving
 `Generic` instances on hand, it's not inconceivable that folks might want
 to do this.

 > Hence, I think this behaviour should be enabled by default, even without
 `Safe` extension.

 I [https://ghc.haskell.org/trac/ghc/ticket/13065 used to share this
 opinion], but I no longer do. I don't think GHC (or `Safe`) should be in
 the business of enforcing the structure of `Generic` instances. You'll
 never segfault from using a hand-written `Generic` instance (unlike, say,
 `Typeable`).

 I think what you want is for GHC to be able to verify that a particular
 `Generic` instance's structure actually matches the data type it was
 derived for. This is a reasonable desire, since there are certain
 properties about data types that can easily be discerned from a `Rep`
 instance, but only if you have confidence that the `Rep` instance isn't
 "lying". dfeuer (cc'd) has toyed with some ideas for how this could be
 achieved in GHC—perhaps he could chime in here.

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


More information about the ghc-tickets mailing list