[plt-scheme] equal? operator

From: Matthew Flatt (mflatt at cs.utah.edu)
Date: Mon Nov 21 17:51:25 EST 2005

At Mon, 21 Nov 2005 16:59:51 -0500, Eli Barzilay wrote:
> The equal? that you're describing is one that can be extended for new
> types (you said that simply overriding `equal?' won't work), and you
> don't want to simply compare all slots recursively (as you get when
> using a proper inspector).  So it seems like what you realy need is a
> generic equal? operation that will do the proper dispatch based on the
> input type, with the ability to define new behaviors for new typs.
> This sounds like something an OO system should let you do.

Or structure-type properties. (That's what we use, for example, to
support customizable object serialization.)

Specifically, we could add a property to MzScheme for setting a struct
type's equality predicate, and `equal?' would check the property for
each struct instance tat it encounters.

The only problems with an equality-test property are the same as in
Java: fitting the equality function into a single-dispatch system, and
supporting a hash-function property whose value must be consistent with
the equality property value. (Are there other issues?)

So, we could change MzScheme --- or you could support a type-specific
equality procedure in your own implementation `equal?', as long as you
control all the uses of `equal?'.


Posted on the users mailing list.