caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Alex Cowie <cowie@cs.unisa.edu.au>
To: caml-list@inria.fr
Subject: Re: [Caml-list] Hashtbl.keys
Date: Fri, 21 Feb 2003 17:10:52 +1030	[thread overview]
Message-ID: <3E55C9F4.2010206@cs.unisa.edu.au> (raw)
In-Reply-To: <20030220104343.B27056@pauillac.inria.fr>

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


      parent reply	other threads:[~2003-02-21  6:41 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-02-18 18:03 Oliver Bandel
2003-02-18 18:13 ` Hal Daume III
2003-02-20  9:43 ` Xavier Leroy
2003-02-20 16:54   ` [Caml-list] OCaml standard library improvement Stefano Zacchiroli
2003-02-21 13:47     ` Nicolas George
2003-02-22 14:09       ` Stefano Zacchiroli
2003-02-23 18:33         ` Alessandro Baretta
2003-02-21 13:53     ` fva
2003-02-21 16:18       ` Amit Dubey
2003-02-21 17:10         ` Brian Hurt
2003-02-21 17:23           ` Nicolas George
2003-02-21 18:01             ` Brian Hurt
2003-02-21 18:57               ` Chris Hecker
2003-02-21 19:28                 ` Brian Hurt
2003-02-22 15:52             ` John Max Skaller
2003-02-21 17:32         ` Maxence Guesdon
2003-02-24  1:21       ` Nicolas Cannasse
2003-02-24  1:45         ` Chris Hecker
2003-02-24  2:46           ` Brian Hurt
2003-02-24  7:42             ` Stefano Zacchiroli
2003-02-24 10:18             ` fva
2003-02-24 11:03             ` Amit Dubey
2003-02-24 12:56               ` John Max Skaller
2003-02-24 13:06                 ` Lauri Alanko
2003-02-24 13:08                 ` Sven Luther
2003-02-24 14:05                   ` [Caml-list] Library Discussion Followups Amit Dubey
2003-02-25  5:49                   ` [Caml-list] OCaml standard library improvement John Max Skaller
2003-02-25  8:29                     ` Xavier Leroy
2003-02-24 16:50                 ` Benjamin C. Pierce
2003-02-24 17:28                   ` brogoff
2003-02-25 18:08                   ` Diego Olivier Fernandez Pons
2003-02-26  7:47                     ` Jean-Christophe Filliatre
2003-02-25 10:47     ` [Caml-list] OCaml standard library _improvement_ NOT a new library! Stefano Zacchiroli
2003-02-25 21:43       ` Alessandro Baretta
2003-02-26  9:42         ` Stefano Zacchiroli
2003-02-21  6:40   ` Alex Cowie [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=3E55C9F4.2010206@cs.unisa.edu.au \
    --to=cowie@cs.unisa.edu.au \
    --cc=caml-list@inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).