I created a type in Haskell which represents a pixel, like so:
data Pixel = Pixel Float Float Int deriving (Eq, Show)
Here, the first float corresponds to the pixel's location on the x axis, the second float represents the location in the y axis (so basically I have 2 coordinates for it on the "screen") and the Int it's its grey value.
I wanted to create and instance of Eq for Pixel in which a pixel is equal to each other if their grey value is the same, regardless of its position.
So far I've done this:
instance Eq Pixel where
but now I don't know how to check if they're the same, I mean, how do I say I have 2 diferent Pixels here and I want to compare their Int? I can't do something like
grey1 == grey2 = True
'cause I don't know where grey1 and grey2 came from.
How can I do it?
Also when doing a instance for Show, how do I refer to the Floats and the Int?
Eqthat only compares on one field, and it's very likely to lead to headaches later if you do anything even slightly complex with it. - Tom Ellis