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

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2003-02-20 (09:43)
From: Xavier Leroy <xavier.leroy@i...>
Subject: Re: [Caml-list] Hashtbl.keys
> 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

- Xavier Leroy
To unsubscribe, mail Archives:
Bug reports: FAQ:
Beginner's list: