Version française
Home     About     Download     Resources     Contact us    
Browse thread
generic Hashtbl.to_array
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Damien Doligez <damien.doligez@i...>
Subject: Re: [Caml-list] generic Hashtbl.to_array

On 2006-07-26, at 04:16, oleg@pobox.com wrote:

> let to_array9 t =
>   let Some (a,_) =
>     Hashtbl.fold (fun k v seed ->
>       match seed with
> 	Some (a,i) -> a.(i) <- (k,v); Some (a,i+1)
>       | None -> let a =  Array.make (Hashtbl.length t) (k,v) in
>                 Some (a,1))
>       t None
>   in a
> ;;

It fails whenever the hash table is empty, and the compiler
warns you about it.  Replace your "let Some (a,_) = ..."
with a pattern-matching and you have a nice solution.

-- Damien