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
modifying hash tables
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2007-07-18 (16:37)
From: Zheng Li <li@p...>
Subject: Re: modifying hash tables
Sam Steingold <> writes:
> I want to modify the _current_ datum in Hashtable.iter, e.g., increment
> a count. Is this code valid?
> Hashtable.iter ht ~f:(fun ~key ~data ->
>   Hashtable.replace ht ~key ~data:(data+1))

If you have associate several datums with the same key, the semantic of the
code is to substitute the current binding of each key with the value of its
earliest binding plus one.

Zheng Li