[project @ 2002-10-18 13:41:50 by simonpj]
authorsimonpj <unknown>
Fri, 18 Oct 2002 13:41:55 +0000 (13:41 +0000)
committersimonpj <unknown>
Fri, 18 Oct 2002 13:41:55 +0000 (13:41 +0000)
commitf53483a24f46fb3aa09052d8c00c0fc5d7d9dcca
tree211b111c4378c4d8f30a6d2d70ab371912c36cd6
parentfbd11e24a1c299bb0c44eb19d1ec75a12d3d685e
[project @ 2002-10-18 13:41:50 by simonpj]
--------------------------------
   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.
ghc/compiler/basicTypes/MkId.lhs
ghc/compiler/typecheck/Inst.lhs
ghc/compiler/typecheck/TcClassDcl.lhs
ghc/compiler/typecheck/TcDeriv.lhs
ghc/compiler/typecheck/TcEnv.lhs
ghc/compiler/typecheck/TcExpr.lhs
ghc/compiler/typecheck/TcInstDcls.lhs