Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] Hash tables keys and values
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Fermin Reig <reig@i...>
Subject: Re: [Caml-list] Hash tables keys and values

> Once I have my hash table complete, I would like to print each key
> with its associated value.  How would I do this?  Right now I only
> have the values:
> 
>    Hashtbl.iter (fun k -> Printf.printf "%d\n") myhash;
> 
> Is there any way I could print both keys and values?
> 
> Thank you,
> Vincent Foley

Read the OCaml manual:

val iter : ('a -> 'b -> unit) -> ('a, 'b) Hashtbl.t -> unit

Hashtbl.iter f tbl applies f to all bindings in table tbl. F RECEIVES
THE KEY AS FIRST ARGUMENT, AND THE ASSOCIATED VALUE AS SECOND
ARGUMENT. The order in which the bindings are passed to f is
unspecied. Each binding is presented exactly once to f.

(My emphasis) Hope that helps,
Fermin
-------------------
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