[clean-list] generic equality?
Pieter Koopman
pieter at cs.ru.nl
Mon Oct 25 12:40:38 MEST 2004
Hi Jerzy,
At 12:01 25-10-2004 +0200, Jerzy Karczmarczuk wrote:
>Forgive me a simplistic question.
>Since in Clean there is no 'deriving' contraption as in Haskell, the
>definition of (simple, identity) equality for instances of the data type
>
>:: Dat = A | B | C | D | E | F | G | H | I | J | K | L | M | N | O
>//... etc.
>
>is the complete set of:
>(==) A A = True
>...
>(==) K K = True
>...
>(==) _ _ = False
>
>which is heavy and inelegant. What are the ways to do it better? The manual
>shows the example of generic constructs, e.g. for lists, which demand
>first the
>conversion of an algebric datatype into sums/products which use Either, etc.
>But with many alternatives the conversion function is also ugly. Do you have
>any other ideas?
Use the predefined generic equality:
module ...
import StdEnv, StdGeneric, GenEq
:: Dat = A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | P
derive gEq Dat
Start = P === K
If you prefer to use == instead of the generic version === you should add:
instance == Dat where (==) x y = x === y
Start = P == K
Ha fun,
Pieter Koopman
More information about the clean-list
mailing list