[clean-list] generic equality?

Arjen van Weelden A.vanWeelden at cs.ru.nl
Mon Oct 25 13:22:51 MEST 2004


Hello,

You can also let the compiler derive the generic equality for your 
datatype, which saves you a lot of work.

The Clean compiler sources contain a fast equality test that does not 
use generics (see compare_constructor.icl):

equal_constructor :: !a !a ->Bool
equal_constructor _ _ = code {
	.inline equal_constructor
		pushD_a 1
		pushD_a 0
		pop_a 2
		eqI
	.end
}

It only tests on the outermost constructor, but it is faster than the 
generic equality.

regards,
	Arjen

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?
> 
> Thanks.
> 
> Jerzy Karczmarczuk
> 
> _______________________________________________
> clean-list mailing list
> clean-list at science.ru.nl
> http://mailman.science.ru.nl/mailman/listinfo/clean-list


More information about the clean-list mailing list