[Haskell-cafe] FunDeps conflict

Brian Hulley brianh at metamilk.com
Tue Jun 6 06:34:37 EDT 2006

Joel Björnson wrote:
> Hi.
> I have a question regarding type classes and FunDeps.
> Consider the following code :
>> class Class2 a b | a -> b
>> class IsFoo a
>> data Bar a = Bar a
>> instance IsFoo a => Class2 a a
>> instance IsFoo a => Class2 (Bar a) a
> The last two instantiations will yield a 'Functional dependencies
> conflict error'. From what I understand, this is because (Bar a)
> *MAY* instantiate the type class isFoo, which would obviously lead to
> a conflict between the two instantiations.

The typeclass IsFoo is irrelevant to the fundep.
The problem arises here:

class Class2 a b | a -> b

data Bar a = Bar a

instance Class2 a a
instance Class2 (Bar a) a

because a and Bar a could be instantiated to two different types eg Bool and 
Bar Bool, yet the result type would be the same, but the fundep specifies 
that the 'a' type uniquely determines the 'b' type, hence the conflict.

> Is there anyway to get around this, knowing that (Bar a) won`t
> instantiate the isFoo class, or is the right answer simply to get rid
> of the FunDep ?

If 'b' is not uniquely determined by 'a' in all instances of Class2 a b, 
then you'd need to get rid of the fundep.

Regards, Brian.
Logic empowers us and Love gives us purpose.
Yet still phantoms restless for eras long past,
congealed in the present in unthought forms,
strive mightily unseen to destroy us.


More information about the Haskell-Cafe mailing list