Frank wrote:
I have observed the error message (ghci 6.4)

Functional dependencies conflict between instance declarations:
     LocTest.hs:16:0: instance B S Bool
     LocTest.hs:22:0: instance (F f, B a b) => B (f a) (f b)

when I changed in an instance from a simple type to a type with a
parameter (i.e. from Int to (Int, Bool)).

The following minimal program demonstrates the problem:

an instance with type S (= T Float) conflicts with B (f a) (f b)

whereas the comparable instance with data R (= R Float) does not.

Is this intentional? How can it be avoided?
Help is greatly appreciated!

Andrew

----------------------------------------
class  F f where
   m2 :: (a -> b -> c) -> f a -> f b -> f c        --zipWith

class B a b | a -> b where
   dist2 :: a -> a -> b

instance B S Bool where -- line 16
   dist2 a d = True

instance B R Float where
   dist2 a d = 1

instance (F f, B a b) => B (f a) (f b) where -- line 22
   dist2 a b = m2 dist2 a b

data T f = T f
type S = T Float
data R = R Float

Suppose you later declared T as an instance of F so that one particular F f would be F T.

Then if S = T Float then one instantiation of (f a) could be (T a) where f = T, so the two instantiated instance decls would look like:

instance B (T Float) Bool where -- line 16
instance B (T a) (T b) where -- line 22

and the functional dependency says that the 'b' (in the class decl) would be Bool by line 16 and T b for some b by line 22 if 'a' was instantiated to Float. However there is no 'b' such that Bool = T b.

Regards, Brian.
_______________________________________________
Haskell-Cafe mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to