overlapping instances and functional dependencies

Hal Daume t-hald@microsoft.com
Fri, 8 Aug 2003 16:53:43 -0700


Suppose somewhere we have an instance:

 instance C Int Bool Int

when the first instance decl you have says we also have

  instance C Int (x,y,Bool) Int

in this case, Int + (x,y,Bool) should uniq. specify Int.

however, we also have:

  instance C a (a,c,b) c

where, if we let a=3DInt, b=3DBool, c=3DChar, then we get that
  Int + (Int,Char,Bool) should uniq. specify Char.

these two confict because if, in the first case, we instantiate x to Int
and y to Char, then one says that the third param should be a Bool and
the other says the third param should be a Char.

(or at least this is my understanding -- someone might correct me)

 - Hal

 --
 Hal Daume III                                   | hdaume@isi.edu
 "Arrest this man, he talks in maths."           | www.isi.edu/~hdaume


> -----Original Message-----
> From: haskell-admin@haskell.org=20
> [mailto:haskell-admin@haskell.org] On Behalf Of Wolfgang Jeltsch
> Sent: Friday, August 08, 2003 4:33 PM
> To: The Haskell Mailing List
> Subject: overlapping instances and functional dependencies
>=20
>=20
> Hello,
>=20
> I have this code:
>     class C a b c | a b -> c where
>         f :: a -> b -> c
>=20
>     instance C a b c =3D> C a (x,y,b) c where
>         f a (_,_,b) =3D f a b
>=20
>     instance C a (a,c,b) c where
>         f _ (_,c,_) =3D c
> ghci -fglasgow-exts -fallow-overlapping-instances compiles it without=20
> complaint but hugs -98 +o says:
>     ERROR "ClassProblem.hs":7 - Instances are not consistent=20
> with dependencies
>     *** This instance    : C a (a,b,c) b
>     *** Conflicts with   : C a (b,c,d) e
>     *** For class        : C a b c
>     *** Under dependency : a b -> c
> Can anyone tell me what the reason for this is and, maybe,=20
> how to avoid these=20
> problems with Hugs?
>=20
> Wolfgang
>=20
> _______________________________________________
> Haskell mailing list
> Haskell@haskell.org
> http://www.haskell.org/mailman/listinfo/haskell
>=20