Browse thread
[Caml-list] Should be INSIDE STANDARD-LIB: Hashtbl.keys
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
| Date: | -- (:) |
| From: | John Goerzen <jgoerzen@c...> |
| Subject: | Re: [Caml-list] Should be INSIDE STANDARD-LIB: Hashtbl.keys |
On Fri, Apr 23, 2004 at 10:31:36PM +0100, Jon Harrop wrote: > I should also say that I have never had any need for this function. What do > you guys use it for? One example is the sections function at http://gopher.quux.org:70/devel/missinglib/html/ConfigParser.rawConfigParser.html. Internally, a configuration file is represented as a hash of section names to a hash of option names to values. (A hash of a hash of strings, basically.) Sometimes, you might not know what sections to expect up-front. Getting a list of the keys in the top-level hash will return the needed information. This could occur for many reasons: configuring multiple ISP accounts in a network tool, configuring multiple database sources in an ODBC configuration, etc. Here's a contrived example, but one I could imagine encountering: Having a hash mapping filenames to data about them (say, from stat(2). Perhaps you'd have a need sometimes to just get a list of files (maybe to copy them elsewhere or display a list for the user). Yes, one could use fold to do all of this. Point is, it's often easier to just call "keys" and get a list. The raw performance may not always matter. (Just witness the popularity of Ruby <g>) -- John ------------------- 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