equality

Ken Sailor sailor@sask.trlabs.ca
Fri, 4 Jul 1997 10:46:36 -0600 (CST)


> 
> Or rather, why isn't there a predefined equality operator
> on all types, that merely checks whether the normal forms
> of its arguments are structurally the same.
> This operator could easily be implemented in a way that
> exploits token-identity.
> 

This goes right to the heart of the development of classes for Haskell 
(and Clean, of course).  Equality does not make sense for many types, the 
primary example being function types.

For example, (and forgive my lack of real syntax!) the increment function 
is equal to the partial application of plus to 1.  How could an equality 
test determine they were the same?  You can think of lots of examples 
where equal functions do not have the same normal forms.

Anyway, in the bad old days, equality was defined for all types, but
would/could return false or an error for inappropriate application.  This
was, in fact, seen to be a hole in the type system. In these good new days,
equality has a definition that is sound in the sense that you can not 
apply it to an argument it shouldn't be applied to.

Granted, since x==x for all x for standard equality you could have an
incomplete definition of equality for any type, but such a definition would
complicate reasoning about programs.  Think of (or read about, for that
matter) equality in Eiffel.  I dislike the idea that programmers would have
to remember which equality applied in given applications on the same 
type. 

Ken