RE: functional dependencies - bug?

Christian This is clearly a bug in 5.03. However, it works fine in the (about to be released) 5.04. 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] | Sent: 28 June 2002 18:09 | To: glasgow-haskell-users@haskell.org | Subject: functional dependencies - bug? | | | Hi, | | does anybody have experiences with "Type Classes with | Functional Dependencies" (LNCS 1782, ESOP 2000, March 200, by | Mark P. Jones)? | | I've tried the example in the above paper: | | class Collects e ce | ce -> e where | empty :: ce | insert :: e -> ce -> ce | member :: e -> ce -> Bool | | This works correctly for: | | instance Eq a => Collects a [a] where | instance Collects Char Int where | | and complains correctly for: | | instance Collects Char Int where | instance Collects Bool Int where | | with "Functional dependencies conflict between instance declarations" | | Now to my problem with a context in the class declaration: | | class Eq ce => Collects e ce | ce -> e where | empty :: ce | ... | | This works as above, but correctly complains for: | | data Stupid = Stupid -- without equality | instance Collects Bool Stupid where | | with "No instance for (Eq Stupid)". | | However, if I supply an (admittingly stupid) default | definition for "empty" within the class declaration: | | class Eq ce => Collects e ce | ce -> e where | empty :: ce | empty = error("empty") | ... | | I no longer get the above "No instance for (Eq | Stupid)"-Message, and I guess that is a bug (or a feature | that I don't understand). | | When I change the context to "Eq e" everything is fine again: | | instance Collects Stupid Int where | | complains as above. | | I don't know when (even meaningful) default definitions cause | that context conditions are not checked. In fact I noticed | this error only after I've removed a default definition just | to find out that my instance declaration were wrong that | seemed to be correct before (but instances for contexts were missing). | | Are there any other (known) pitfalls with functional dependencies? | | Regards Christian _______________________________________________ | Glasgow-haskell-users mailing list | Glasgow-haskell-users@haskell.org | http://www.haskell.org/mailman/listinfo/glasgow-| haskell-users |

Hi, please consider the following example (from Mark P. Jones: "Type Classes with Functional Dependencies" LNCS 1782, ESOP 2000), that I've extended with a function "one": class Collects e ce | ce -> e where empty :: ce insert :: e -> ce -> ce member :: e -> ce -> Bool one :: ce -> e -- added just for the sake of demonstration The following function was ok for GHC version 5.02.3: info :: (Collects e ce, Show e) => ce -> String info v = show (one v) However, when I tried to mention the element type "e", that does not occurr in the result type, I got the following error for "show ((one v)::e)": Could not deduce (Collects e ce) from the context () Probable fix: Add (Collects e ce) to the the type signature of an expression arising from use of `one' at Collects.hs:11 In an expression with a type signature: (one v) :: forall e. e In the first argument of `show', namely `((one v) :: forall e. e)' (It did also not help to write "show ((one v)::Collects e ce => e)" Because "ce" determines the type "e" via the functional dependency in "Collects", I think "e" should not be changed/generalized to "forall e. e". (You may think, that "e" should not be mentioned at all, if it is not part of the functionality.) At least the behaviour of GHC seems to be inkonsistent, as it should be possible to supply type signatures to (sub-)expressions. Regards Christian P.S. duplicate "the"-typo in: Add (Collects e ce) to the the type signature of an expression ^^^^^^^
participants (2)
-
Christian Maeder
-
Simon Peyton-Jones