Reputation: 2738
I apologize for this question. I've been away for a while and feel like I've forgotten everything I knew.
I want to do something like this.
data X = X
data Y = Y
myEq X X = True
myEq Y Y = True
myEq _ _ = False
I've tried various declarations for myEq
. I've also tried to define a type class that might do it. But nothing I could think of compiled.
Is something like this possible? And if so, how?
Thanks.
Upvotes: 0
Views: 127
Reputation: 2738
I think this will do it.
data X = X deriving (Show)
data Y = Y deriving (Show)
class (Show a) => MyEquatable a
instance MyEquatable X
instance MyEquatable Y
myEq :: (MyEquatable a, MyEquatable b) => a -> b -> Bool
myEq a b = show a == show b
Of course, if doesn't have to be show
, but that's a simple way to do it.
Upvotes: 1