I have defined a datatype for which I allow GHC to automatically derive an instance of the Eq typeclass.
However, the derived instance doesn't have the precise behavior I need for all cases.
For instance, see this datatype:
data IntegerOrFloat = I Integer | F Float
deriving Eq
(I 0) == (F 0) evaluates to False. I would like it to evaluate to true. If I were writing the implementation I could simply do:
instance Eq IntegerOrFloat where
(I i) == (F f) = (fromIntegral i) == f
However, I would then have to write the other three cases. Obviously this would be trivial for this type, but this is a contrived example. I very much prefer the convenience of leaving most cases automatically derived.
Is there a way for me to "override" the derived implementation for a specific case, without having to write the entire implementation by hand?