-
Simon Peyton Jones authored
-------------------------------- Fix a serious error in the "newtype deriving" feature -------------------------------- The "newtype deriving" feature lets you derive arbitrary classes for a newtype, not just the built-in ones (Read, Show, Ix etc). It's very cool, but Hal Duame discovered that it did utterly the Wrong Thing for superclasses. E.g. newtype Foo = MkFoo Int deriving( Show, Num, Eq ) You'd get a Num instance for Foo that was *identical* to the Num instance for Int, *including* the Show superclass. So the superclass in the Num dictionary would show a Foo just like an Int, which is wrong... it should show as "Foo n". This commit fixes the problem, by building a new dictionary every time, but using the methods from the dictionary for the representation type. I also fixed a bug that prevented it working altogether when the representation type was not the application of a type constructor. For example, this now works newtype Foo a = MkFoo a deriving( Num, Eq, Show ) I also made it a bit more efficient in the case where the type is not parameterised. Then the "dfun" doesn't need to be a function.
f53483a2