On Sun, Feb 27, 2005 at 03:36:42PM -0700, Luke Palmer wrote:
> But the biggest problem is that if the user overloads 'equal' on two
> objects, the hash should consider them equal. We could require that to
> overload 'equal', you also have to overload .hash so that you've given
> some thought to the thing. The worry I have is that people will do:
>
> method hash() { 0 }
This is why I think a 'canonicalize' method is better than a
.hash' method: if canonicalize is defined correctly, then .equal
is just {$a.canon() is_bitwise_identical_to $b.canon()}, so
people don't have to supply both. Quite often when you would ordinarily
define a .equal method, it is of that form anyhow. And then .hash
can be straightforwardly defined as {$_.canon().binaryhash()}, where
binaryhash() just means hash all the memory of this object.
Stringify would be an instance of a canonicalization function; and
perhaps the default.
Alex