functional dependencies - bug?
Simon Peyton-Jones
simonpj@microsoft.com
Mon, 1 Jul 2002 16:41:07 +0100
Christian
This is clearly a bug in 5.03. =20
However, it works fine in the (about to be released) 5.04.=20
My plan, therefore, is to add it to our regression test suite
and delcare victory. If I was being totally thorough I'd find
out what went wrong in 5.03, in case it's still wrong in 5.04, but
I'm not going to be totally thorough!
Please yell if any similar mysterious things happen. I appreciate
the report.
Simon
| -----Original Message-----
| From: Christian Maeder [mailto:maeder@Informatik.Uni-Bremen.DE]=20
| Sent: 28 June 2002 18:09
| To: glasgow-haskell-users@haskell.org
| Subject: functional dependencies - bug?
|=20
|=20
| Hi,
|=20
| does anybody have experiences with "Type Classes with=20
| Functional Dependencies" (LNCS 1782, ESOP 2000, March 200, by=20
| Mark P. Jones)?
|=20
| I've tried the example in the above paper:
|=20
| class Collects e ce | ce -> e where
| empty :: ce
| insert :: e -> ce -> ce
| member :: e -> ce -> Bool
|=20
| This works correctly for:
|=20
| instance Eq a =3D> Collects a [a] where
| instance Collects Char Int where
|=20
| and complains correctly for:=20
|=20
| instance Collects Char Int where
| instance Collects Bool Int where=20
|=20
| with "Functional dependencies conflict between instance declarations"
|=20
| Now to my problem with a context in the class declaration:
|=20
| class Eq ce =3D> Collects e ce | ce -> e where
| empty :: ce
| ...
|=20
| This works as above, but correctly complains for:
|=20
| data Stupid =3D Stupid -- without equality
| instance Collects Bool Stupid where
|=20
| with "No instance for (Eq Stupid)".
|=20
| However, if I supply an (admittingly stupid) default=20
| definition for "empty" within the class declaration:
|=20
| class Eq ce =3D> Collects e ce | ce -> e where
| empty :: ce
| empty =3D error("empty")
| ...
|=20
| I no longer get the above "No instance for (Eq=20
| Stupid)"-Message, and I guess that is a bug (or a feature=20
| that I don't understand).
|=20
| When I change the context to "Eq e" everything is fine again:
|=20
| instance Collects Stupid Int where
|=20
| complains as above.
|=20
| I don't know when (even meaningful) default definitions cause=20
| that context conditions are not checked. In fact I noticed=20
| this error only after I've removed a default definition just=20
| to find out that my instance declaration were wrong that=20
| seemed to be correct before (but instances for contexts were missing).
|=20
| Are there any other (known) pitfalls with functional dependencies?
|=20
| Regards Christian _______________________________________________
| Glasgow-haskell-users mailing list=20
| Glasgow-haskell-users@haskell.org=20
| http://www.haskell.org/mailman/listinfo/glasgow-| haskell-users
|=20