From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id HAA26094; Fri, 21 Feb 2003 07:41:50 +0100 (MET) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id HAA26041 for ; Fri, 21 Feb 2003 07:41:49 +0100 (MET) Received: from reason.levels.unisa.edu.au (reason.levels.unisa.edu.au [130.220.33.11]) by nez-perce.inria.fr (8.11.1/8.11.1) with ESMTP id h1L6flH08677 for ; Fri, 21 Feb 2003 07:41:47 +0100 (MET) Received: from cs.unisa.edu.au (octal.levels.unisa.edu.au [130.220.39.199]) by reason.levels.unisa.edu.au (8.9.3/8.9.3) with ESMTP id RAA31455; Fri, 21 Feb 2003 17:11:42 +1030 (CST) Message-ID: <3E55C9F4.2010206@cs.unisa.edu.au> Date: Fri, 21 Feb 2003 17:10:52 +1030 From: Alex Cowie User-Agent: Mozilla/5.0 (Windows; U; WinNT4.0; en-US; rv:0.9.4) Gecko/20011128 Netscape6/6.2.1 X-Accept-Language: en-us MIME-Version: 1.0 To: caml-list@inria.fr Subject: Re: [Caml-list] Hashtbl.keys References: <20030218180341.GA267@first.in-berlin.de> <20030220104343.B27056@pauillac.inria.fr> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk 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