[
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: | 2006-07-26 (09:48) |
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