[GHC] #15434: DerivingVia (and perhaps even GND) works badly with DeriveGeneric
GHC
ghc-devs at haskell.org
Thu Jul 26 04:54:48 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: |
-------------------------------------+-------------------------------------
Comment (by konn):
Replying to [comment:3 RyanGlScott]:
> True, 90% of the time, this is what you want, but for the other 10%,
having explicit control through `DerivingStrategies` is quite handy.
I agree. In general, it is desirable to have the flexibility on the choice
of a deriving strategy.
> 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.
I've just taken a simple survey searching `instance Generic` in codes on
GitHub and count how many custom instances for `Generic` are defined,
using [https://github.com/konn/crawl-github this code].
It reported that there are 2 out of 892 modules with custom `Generic`
instance and have 12 custom instances as a total; it turns out that
`Generic` instances in one of the modules are not related to GHC's
Generics.
One instance is something like mapping the Rep of `Map k v` to that of
`[(k, v)]`. Since there are some modules that cannot be parsed by
`haskell-src-exts` and not counted in my survey, there might be more
custom instances.
Anyway, there is at least one use-case and there might be other custom
instances doing the similar things.
> 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.
I find this option is reasonable. If GHC can warn that one can avoid
unintended derived instance, and if one really wants to write custom
instance, then one can turn off that warning.
--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/15434#comment:4>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
More information about the ghc-tickets
mailing list