[GHC] #13328: Foldable, Functor, and Traversable deriving handle phantom types badly
GHC
ghc-devs at haskell.org
Tue Mar 7 01:10:25 UTC 2017
#13328: Foldable, Functor, and Traversable deriving handle phantom types badly
-------------------------------------+-------------------------------------
Reporter: dfeuer | Owner: (none)
Type: bug | Status: new
Priority: normal | Milestone: 8.4.1
Component: Compiler | Version: 8.1
Resolution: | Keywords: deriving-perf
Operating System: Unknown/Multiple | Architecture:
Type of failure: Runtime | Unknown/Multiple
performance bug | Test Case:
Blocked By: | Blocking:
Related Tickets: | Differential Rev(s):
Wiki Page: |
-------------------------------------+-------------------------------------
Comment (by RyanGlScott):
There's one more scenario that this proposed change would wreak havoc
with. It's quite possible for users to define unlawful `Functor` instances
and depend on them in other derived `Functor` instances:
{{{#!hs
newtype Unlawful a = Unlawful Int
instance Functor Unlawful where
fmap f (Unlawful i) = Unlawful (i + 1)
newtype WrapUnlawful a = WrapUnlawful (Unlawful a)
deriving Functor
}}}
But under this proposal, the generated `Functor` instance for
`WrapUnlawful` would be:
{{{#!hs
instance Functor WrapUnlawful where
fmap _ = coerce
}}}
This would be another departure in behavior, as now `fmap`ping over a
`WrapUnlawful` wouldn't apply `(+1)` to the field of the `Unlawful` (icky
as it may be).
--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/13328#comment:5>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
More information about the ghc-tickets
mailing list