[GHC] #13065: Prohibit user-defined Generic and Generic1 instances
GHC
ghc-devs at haskell.org
Wed Jan 4 17:26:36 UTC 2017
#13065: Prohibit user-defined Generic and Generic1 instances
-------------------------------------+-------------------------------------
Reporter: dfeuer | Owner:
Type: feature | Status: new
request |
Priority: normal | Milestone: 8.4.1
Component: Compiler | Version: 8.0.1
Keywords: Generics | Operating System: Unknown/Multiple
Architecture: | Type of failure: Other
Unknown/Multiple |
Test Case: | Blocked By:
Blocking: | Related Tickets:
Differential Rev(s): | Wiki Page:
-------------------------------------+-------------------------------------
User-defined `Generic` and `Generic1` instances are problematic.
=== They are susceptible to breakage ===
Some details of the classes may change between GHC versions, and indeed
have done so in the past. User-defined instances are likely to break in
the face of various such "internal" changes. This is one reason why
`Data.Sequence`, for example, does not have a `Generic` instance.
=== They require potentially-expensive consistency checks ===
GHC cannot assume that every type has at most one `Generic` and `Generic1`
instance, so it needs to look for possible alternatives at instance
resolution time. According to Simon (and maybe also Simon), this may be
partly responsible for the performance regressions seen in Phab:D2899.
=== Downsides ===
Prohibiting user-defined instances does have some costs. Suppose a type
was originally defined concretely, exposing its constructors and a
`Generic` instance. The implementer may decide later to make the type
abstract, and export pattern synonyms to retain the same interface. But
the `Generic` instance will either change or disappear. Someone relying on
that instance could be in trouble. If the instance disappears, they'll be
forced to write code by hand that they didn't need to before. If it
changes, their code may change its behavior unexpectedly.
--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/13065>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
More information about the ghc-tickets
mailing list