Version française
Home     About     Download     Resources     Contact us    
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: -- (:)
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
>>too.
>>
> 
> 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 caml-list-request@inria.fr Archives: http://caml.inria.fr
> Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
> 
> 


-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners