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] Should be INSIDE STANDARD-LIB: Hashtbl.keys
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2004-04-23 (21:53)
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
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 Archives:
Bug reports: FAQ:
Beginner's list: