Consider the following types:
data MyType = MyType Val Col deriving (Eq, Show)
data Val = Val A | B | C deriving (Eq, Ord, Show, Read)
data Col = X | Y | Z deriving (Eq, Ord, Show, Read)
If I now have a function like sameVal :: MyType -> MyType -> Bool
that is supposed to check the Val
field for equality and try to do it like this:
sameVal (MyType v _) (MyType v _) = True
sameVal _ _ = False
GHC whines at me telling me that v
has conflicting definitions...
Conflicting definitions for ‘v’
Bound at: htest.hs:6:14
htest.hs:6:24
In an equation for ‘sameVal’
but its supposed to imply that they have to be the same. What am I not getting here?
Note: I get that I could just give them different names and compare v1
and v2
later in the function body. This question is about pattern-matching in general, not this specific example.
Tank's for any Help.