[Haskell-cafe] Eq macro which matches anything

Ivan Lazar Miljenovic ivan.miljenovic at gmail.com
Sat Dec 5 01:46:06 UTC 2015


On 5 December 2015 at 09:02, frantisek kocun <frantisek.kocun at gmail.com> wrote:
> Hi guys,
>
> I'm doing Write yourself Scheme tutorial. And for testing it would be cool
> to have some kind of macro.
>
> -- My data type with Eq derived
> data LispError = NumArgs Integer [LispVal]
>                | TypeMismatch String LispVal
>                | Parser ParseError
>                | BadSpecialForm String LispVal
>                | NotFunction String String
>                | UnboundVar String String
>                | Default String
>                deriving (Eq)
>
> -- I can call ==
> NumArgs 1 [] == NumArgs 1 []
>
> -- but sometimes I want to do (I know I can implement my own Eq, but I want
> to use both forms)
> NumArgs 1 [] == NumArgs 1 _
>
> where I omit second parameter. I think derived Eq where it matches all the
> args is fine I just need to do macro which will get whateverType by compiler
> and always return True in Equality check. Do you think it is possible to do?
> I use Mockito library in java but java is OO, so completely different beast.
>
> Thank you

You could always define a new function:

eqError :: LispError -> LispError -> Bool
eqError (NumArgs n1 _) (NumArgs n2 _) = n1 == n2
eqError TypeMisMatch{} TypeMismatch{} = True
-- etc.

>
>
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
>



-- 
Ivan Lazar Miljenovic
Ivan.Miljenovic at gmail.com
http://IvanMiljenovic.wordpress.com


More information about the Haskell-Cafe mailing list