functional dependency problem

Christian Maeder maeder@Informatik.Uni-Bremen.DE
Mon, 08 Jul 2002 18:54:00 +0200


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

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

    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

duplicate "the"-typo in:
        Add (Collects e ce) to the the type signature of an expression