Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
Alternative generic hash function
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2000-05-25 (07:27)
From: Pierre Weis <Pierre.Weis@i...>
Subject: Re: Alternative generic hash function
> The generic hash function Hashtbl.hash traverses into mutable data
> structures. So I get different hash values depending on updates of the data
> structure. 
> As was pointed out times before on this list, Hashtbl.hash is thus
> unsuitable for hashing on data structures that contain mutable data.
> I'm wondering what the design rational is for this choice. I'd rather have a
> generic hash function (Hashtbl.hash_pure) that never looks into mutable
> structures (skips refs and mutable fields of records and classes).

The rationale is simple: there is no way to distinguish between
mutable and immutable data structures at runtime. So, there is no
possibility to implement the suggested hash_pure function in a
polymorphic way. If you really want to use keys that belong to a
mutable data structure (which is not a good idea anyway), you should
use the functorial interface to hash tables to specify your own
hashing function, that would implement hash_pure on your particular
key type.

Best regards,

Pierre Weis

INRIA, Projet Cristal,