overlapping instances and functional dependencies

Tom Pledger Tom.Pledger@peace.com
Fri, 22 Aug 2003 09:24:14 +1200


C T McBride writes:
 :
 | but I'm not allowed
 | 
 |   class Bad x y z | x y -> z
 | 
 |   instance Functor f => Bad (f x) (f y) Bool
 | 
 |   instance Functor f => Bad x (f y) Int
 | 
 | I don't quite see why. Naively, I imagine that if the OK instances are
 | effectively prioritized, then Bad's rules for computing z from x and y
 | could be similarly prioritized. Can anyone explain why this naive
 | imagining is incorrect?

Hi.

The first instance decl includes

    instance Bad [()] [()] Bool

and the second includes

    instance Bad [()] [()] Int

which break the functional dependency because x and y do not uniquely
determine z.

But I suspect you already knew that, and were asking why the
functional dependency feature is based on uniqueness constraints, not
prioritised type-computation rules.  I'm not sure of the original
reason, but the uniqueness approach supports some neat tricks

    http://www.willamette.edu/~fruehr/haskell/evolution.html#fundep

which the prioritised approach probably wouldn't.

Regards,
Tom