Hi,

How does the context of a class instance declaration affect its subclasses?

The Num class instance outlined below has its requirement for Eq and Show 
satisfied on the preceding lines, and the code will compile. But if I, say, add 
an (Eq a) constraint to the Eq instance, in preparation for a simple (==) 
definition, I find that the Num instance declaration is left lacking. If I add 
the same (Eq a) constraint now to Num, calm is restored.

data Foo a = F a

instance Eq (Foo a) where
 (==) = undefined

instance Show (Foo a) where
 show = undefined

instance Num (Foo a)
 (+) = undefined
 ... etc.

The thing that confuses me with this is that it seems like Num "knows" that an 
(Eq a) context has been applied, and so what it sees as a problem, is somehow 
also the solution. Any advice/rules of thumb? Does this situation occur 
elsewhere? How do these constraints propagate?

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

Reply via email to