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:35)
From: STARYNKEVITCH Basile <Basile.Starynkevitch@c...>
Subject: Alternative generic hash function
>>>>> "Manuel" == Manuel Fahndrich <> writes:

    Manuel> The generic hash function Hashtbl.hash traverses into
    Manuel> mutable data structures. [...]

    Manuel> As was pointed out times before on this list, Hashtbl.hash
    Manuel> is thus unsuitable for hashing on data structures that
    Manuel> contain mutable data.

    Manuel> I'm wondering what the design rational is for this
    Manuel> choice. I'd rather have a generic hash function
    Manuel> (Hashtbl.hash_pure) that never looks into mutable
    Manuel> structures (skips refs and mutable fields of records and
    Manuel> classes).  

I disagree. And it is probably difficult to implement in current Ocaml
(which lacks any reflective facilities). The runtime does not know
about mutable fields! If I want to hash mutable data structure, I will
provide a specific hashing function.

What I am lacking of is an hashing function accepting parametric
type. I would like to define

type 'a symbol_t = { sym_name: string; sym_hash: int; sym_val: 'a option}

Then have

let make_symbol s = { sym_name= s; sym_hash= Hashtbl.hash s; sym_val= None}

let hash_symbol { sym_hash= h } = h 

Unfortunately I cannot make an hashtable using hash_symbol as hashing

Actually, hashing is a difficult subject. Perhaps there should be
several hashing modules in Ocaml stdlib?


N.B. Any opinions expressed here are only mine, and not of my organization.
N.B. Les opinions exprimees ici me sont personnelles et n engagent pas le CEA.

Basile STARYNKEVITCH   ----  Commissariat à l Energie Atomique 
DTA/LETI/DEIN/SLA * CEA/Saclay b.528 (p111f) * 91191 GIF/YVETTE CEDEX * France
phone: 1,; fax: home: 1,
email: Basile point Starynkevitch at cea point fr