[Haskell-cafe] Eq macro which matches anything
b at chreekat.net
Sat Dec 5 18:49:58 UTC 2015
On Fri, Dec 4, 2015 at 2:02 PM, frantisek kocun <frantisek.kocun at gmail.com>
> -- (I know I can implement my own Eq, but I want to use both forms)
The two computations are very different. Since the type of a value
determines which "Eq" computation to run, it is not advisable to try to get
two different computations to work for the same type.
What you can do instead is use a newtype:
-- | A variant that ignores the LispVal in NumArgs for Eq
newtype LispErrorI = LispErrorI LispError
instance Eq LispErrorI where
(LispErrorI (NumArgs n _)) == (LispErrorI (NumArgs n' _)) = n == n'
(LispErrorI e) == (LispErrorI e') = e == e'
Anytime you want to compare two LispError:s using the second computation,
you can wrap / unwrap the values in the newtype. It creates some extra
syntax noise, but it makes the intent very clear, and there's no runtime
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Haskell-Cafe