About fundeps

Lennart Augustsson [email protected]
Wed, 10 Jan 2001 05:03:26 -0500


Anton Moscal wrote:

> Hello!
>
> When I apply hugs to the following program:
>
> import Char (ord) class Conv a b | a -> b where conv:: a -> b
> instance Conv Char Int where conv = ord
> instance (Conv a b, Conv b c) => Conv a c where conv = conv . conv
>
> Hugs reports:
>
> ERROR "fdep.hs" (line 4): Instances are not consistent with dependencies
> *** This instance : Conv a b
> *** Conflicts with : Conv Char Int
> *** For class : Conv a b
> *** Under dependency : a -> b
>
> But why?

Because they aren't.
Assume you have
> instance Char Int
and also
> instance Int Float
According to your second instance declaration you now also have
> instance Char Float
But the functional dependency states that the first parameter uniquely
determines the second and now there are two conflicting instances
for Char.

    -- Lennart