[clean-list] How can I define an equality test ?
pieter at cs.ru.nl
Mon Nov 26 08:42:44 MET 2007
there are two ways to define equality for an algebraic data type:
1) Define it yourself as Jerzy wrote:
At 11:13 PM 11/25/2007, jerzy.karczmarczuk at info.unicaen.fr wrote:
>Unless I am wrong, you cannot count on any intelligence of the compiler...
>(==) Monday Monday = True
>(==) Tuesday Tuesday = True
>(==) _ _ = False // otherwise
2) Using generics as Ben wrote:At 12:44 AM 11/26/2007, Ben Lippmeier wrote:
>I had the same problem some time ago. You can use the clean generics
>library to derive the equality operator (===) that you want. See the
>mail archive at:
derive gEq Day
instance == Day where (==) x y = x === y
This implementation would be somewhat less efficient.
By the way, a simpler definition of your function isGood is:
isGood Mon = True
isGood _ = False
At 04:49 PM 11/23/2007, Ferreira Maurizio wrote:
>Im trying to define the == operator
>with an algebraic data type.
>How can I define it ?
>what have I to write i the following example, instead of ????
>:: Day = Mon | Tue | Wed | Thu | Fri | Sat | Sun
>instance == Day
> (==) :: Day Day -> Bool
> (==) x y = x ????? y //// what have I to write ?
>IsGood :: Day -> Bool
>IsGood x = x == Mon
>Start = IsGood Mon
>clean-list mailing list
>clean-list at science.ru.nl
More information about the clean-list