Reputation: 211
I am trying to implement Eq class type for the following data:
data Pair a = Pair a a
instance Eq a => Eq (Pair a) where
(==) (Pair x x) (Pair y y) = (x == y)
I am getting the following error message:
Conflicting definitions for ‘y’ in ....
My questions:
y
, why there isn't a similar error for x
?Upvotes: 1
Views: 89
Reputation: 2089
Say the following call is being made:
(Pair 1 2) == (Pair 3 4)
The value 1 will be assigned to x at this point:
(==) (Pair x...
At this point x is being reassign to the value 2 which is not allowed:
(==) (Pair x x...
Hence the error
As for the answer to your second question, you should have gotten an error for both x, and y, like so:
Test.hs:6:16:
Conflicting definitions for `x'
Bound at: Test.hs:6:16
Test.hs:6:18
In an equation for `=='
Test.hs:6:27:
Conflicting definitions for `y'
Bound at: Test.hs:6:27
Test.hs:6:29
In an equation for `=='
Upvotes: 3