Anomalous Class Fundep Inference
Simon Peyton-Jones
simonpj@microsoft.com
Thu, 3 May 2001 01:42:10 -0700
| In Hugs 98 Feb2001 (as hugs -98), this piece of code gives an error:
|=20
| class X a b | a -> b where x :: a;
| class (X a b) =3D> Y a b | a -> b where y :: a;
| instance (X a b) =3D> Y a b where y =3D x;
| instance (Num a) =3D> X a a where x =3D 0; -- line A
Quite right too! The final instance declaration says that the two
arguments of X must always be the same:
* the class says a->b
* the instance matches any first arg and says that
the second must be equal.
So when typechecking the instance for Y a b, a and b are forced
to be equal, and that's less general than the instance claims to
be.
Simon