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
[Caml-list] Hashtbl.keys
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2003-02-21 (06:41)
From: Alex Cowie <cowie@c...>
Subject: Re: [Caml-list] Hashtbl.keys
The documentation of Hashtbl.iter and Hashtbl.fold states:
	The order in which the bindings are passed to f is unspecified. 	
	Each binding is presented exactly once to f.
Given that other operations on Hashtbl preserve the reverse order of 
introduction for bindings for a particular key value, do iter and fold 
also preserve the (reverse) order of introduction for bindings for a 
particular key.  Without a guarantee of this partial ordering, iter and 
fold would be much less useful in constructing map and similar 
transformations on tables where multiple bindings for a key are allowed. 
    If the partial ordering does hold, can this be added to the 
documentation of iter and fold.

If a table is constrained to have only one binding per key (eg through 
using Hashtbl.replace as the add operator) then the lack of ordering 
becomes less of an issue.

Alex Cowie,
School of Computer and Information Science,
University of South Australia.

Xavier Leroy wrote:

>>Well... and Hashtbl.iter seems to work on *all* antries in the
>>*whole* hash-table, that is: A Hastbl.find_all  for each of the
>>keys in that table.
>>At least it is, how I understand the decription in the manual.
>>Well, but Hashtbl.iter is used for unit-functions.
>>But I need bool-functions, and maybe other tyopes
> See Hashtbl.fold, which supports traversing all entries of a hashtable
> and build a result of any type.  For instance:
>>So, Hashtbl.keys would have the following type:
>>('a, 'b) t -> key 'a list
> let keys h = Hashtbl.fold (fun key data accu -> key :: accu) h []
>>Wouldn't it a good idea to add such a
>>function "get all keys of a hashtable"
>>into the hashtbl-module? (And a "get all values..." to?)
> There would be disagreement as what the return type of these functions
> should be: lists, sets, etc.  But you can easily write them with
> Hashtbl.fold.
> - Xavier Leroy
> -------------------
> To unsubscribe, mail Archives:
> Bug reports: FAQ:
> Beginner's list:

To unsubscribe, mail Archives:
Bug reports: FAQ:
Beginner's list: