[GHC] #9757: Warn about derivable instances
GHC
ghc-devs at haskell.org
Mon Nov 3 15:34:00 UTC 2014
#9757: Warn about derivable instances
-------------------------------------+-------------------------------------
Reporter: dfeuer | Owner:
Type: feature | Status: new
request | Milestone:
Priority: normal | Version: 7.9
Component: Compiler | Keywords:
Resolution: | Architecture: Unknown/Multiple
Operating System: | Difficulty: Unknown
Unknown/Multiple | Blocked By:
Type of failure: | Related Tickets:
None/Unknown |
Test Case: |
Blocking: |
Differential Revisions: |
-------------------------------------+-------------------------------------
Comment (by dfeuer):
Replying to [comment:1 goldfire]:
> To my knowledge, GHC can ''not'' derive instances better than anyone
else. Since the advent of `coerce`, `GeneralizedNewtypeDeriving` has no
magic -- any GND instance can be written by hand, sometimes with lots of
type annotations and `ScopedTypeVariables`, though.
I don't ''think'' this is exactly right. As I understand it, `coerce`
should let you hand-build an exact ''copy'' of an existing dictionary, but
`GeneralizedNewtypeDeriving` lets you actually ''reuse'' the dictionary.
> Personally, I would want to see nice definitions of "obviously" and
"equivalent" before thinking too much harder about this. This seems hard
to do and not terribly useful, to me.
It's useful because GHC can derive a lot more things today than in olden
times, and there's a lot of old code that hasn't noticed yet. The notion
of "obviously" is to recognize plain wrap/unwrap patterns, preferably with
enough flexibility to handle both pattern-matching versions and `(.)`
versions and maybe even a little inlining. The scare quotes around
"equivalent" were to recognize the potential for arity mismatches—a hand-
written version may guarantee a certain arity that the GND-derived version
does not.
{{{#!hs
newtype Foo m = Foo m
instance Monoid m => Monoid Foo m where
mempty = Foo mempty
Foo x `mappend` Foo y = Foo (x `mappend` y)
}}}
I'd want this to be recognized as derivable even though it guarantees that
`mappend _|_ = const _|_ /= _|_` while the GND-derived instance would not
make such a guarantee.
--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/9757#comment:2>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
More information about the ghc-tickets
mailing list