develooper Front page | perl.perl6.language | Postings from March 2005

Re: Valid hash keys?

Thread Previous | Thread Next
Alex Burr
March 1, 2005 15:54
Re: Valid hash keys?
Message ID:
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 {$ is_bitwise_identical_to $}, 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 {$}, where
binaryhash() just means hash all the memory of this object. 

 Stringify would be an instance of a canonicalization function; and
perhaps the default.


Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About