In the following example:
data ColourName
= White
| Grey
| Gray
| Black
| Blue
| LastColor
deriving (Read, Show, Eq)
I would like to redefine (==)so that Greythey are Grayevaluated as equals.
Obviously, one way would be to not include Eqin deriving, but then I would need to define
(==) :: ColourName
(==) White White = True
(==) Gray Gray = True
(==) Grey Grey = True
(==) Gray Grey = True
(==) Grey Gray = True
(==) Black Black = True
-- frickin' log of other colors, hundreds of lines of typing
(==) LastColor LastColor = True
(==) a b = False
which I do not plan to do anything.
I also can not do
instance Eq ColourName where
(==) :: ColourName -> ColourName -> Bool
(==) Gray Grey = True
(==) Grey Gray = True
(==) a b = (a == b)
because it leads to infinite recursion, mostly undetermined.
Is there a way out?
(No, I don’t want to use data Colour = Colour Stringor similar. I want acceptable colors to be presented as an enumeration, such as automatic checking, but allowing spelling to be allowed for end users of the module!)
source
share