From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by yquem.inria.fr (Postfix) with ESMTP id 0AE1ABBB7 for ; Wed, 26 Jul 2006 11:48:10 +0200 (CEST) Received: from pauillac.inria.fr (pauillac.inria.fr [128.93.11.35]) by concorde.inria.fr (8.13.6/8.13.6) with ESMTP id k6Q9m9d0025947 for ; Wed, 26 Jul 2006 11:48:09 +0200 Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id LAA31355 for ; Wed, 26 Jul 2006 11:48:09 +0200 (MET DST) Received: from [128.93.8.130] (macadam.inria.fr [128.93.8.130]) by nez-perce.inria.fr (8.13.6/8.13.6) with ESMTP id k6Q9m8hq018364 for ; Wed, 26 Jul 2006 11:48:08 +0200 Mime-Version: 1.0 (Apple Message framework v750) In-Reply-To: <20060726021615.4FF7DA9B1@Adric.metnet.fnmoc.navy.mil> References: <20060726021615.4FF7DA9B1@Adric.metnet.fnmoc.navy.mil> Content-Type: text/plain; charset=US-ASCII; format=flowed Message-Id: Content-Transfer-Encoding: 7bit From: Damien Doligez Subject: Re: [Caml-list] generic Hashtbl.to_array Date: Wed, 26 Jul 2006 11:48:25 +0200 To: caml users X-Mailer: Apple Mail (2.750) X-Miltered: at concorde with ID 44C73A59.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Miltered: at nez-perce with ID 44C73A58.003 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; damien:01 damien:01 hashtbl:01 oleg:01 hashtbl:01 hash:01 compiler:01 2006:98 26,:98 wrote:01 doligez:01 doligez:01 caml-list:01 match:02 let:03 X-Spam-Checker-Version: SpamAssassin 3.0.3 (2005-04-27) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=disabled version=3.0.3 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