equality

veldhvz veldhvz@ipo.tue.nl
Thu, 03 Jul 1997 16:24:09 +0200


A question: "Is it possible to implement in Clean
an operator that checks for token-identity?"

What I mean is this.
As far as I know, the only way of checking whether two
objects are the same in Clean is by using the == operator.
An instance of this operator has to be defined for every 
type on which equality checks are needed.
The only way to define it is by comparing the contents
of the objects, and if they are large datastructures
this can be very time-consuming, while in some cases
it can be done much more effeciently.

For instance,

	f x | x == x     =  1
	    | otherwise  =  0

f should return 1 for any x, for x should always be
identical to itself, regardless of its contents. 

And if x is a huge list (say of a few thousand elements)
then exploiting this fact should save a great deal of
computing power. 
Its like when programming in imperative languages with pointers; 
to check equality you first check the pointers and if they are 
the same then return True, otherwise compare the contents.

Obviously, the programmer could define == for some type so as to 
return False even if the objects are the same, but 
this would not be very useful.

My question is, is there a way to implement the kind of
equality operator that has the property I describe above?
And if not, why is there no standard operation defined
in Clean that checks for token-identity?
Will it be added in one of the future versions?

-- 
Gert Veldhuijzen van Zanten
---------------------------------------------------
IPO, Center for Research on User-System Interaction
phone: +31 40 2475260,          fax: +31 40 2431930             
URL: http://www.tue.nl/ipo/people/veldhvz
e-mail: veldhvz@ipo.tue.nl  
P.O. Box 513, 5600 MB  Eindhoven, the Netherlands     
---------------------------------------------------