From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Delivered-To: caml-list@yquem.inria.fr Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by yquem.inria.fr (Postfix) with ESMTP id D4E13BC2F for ; Sat, 4 Dec 2004 13:19:25 +0100 (CET) Received: from pauillac.inria.fr (pauillac.inria.fr [128.93.11.35]) by nez-perce.inria.fr (8.13.0/8.13.0) with ESMTP id iB4CJPEF004336 for ; Sat, 4 Dec 2004 13:19:25 +0100 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 NAA03139 for ; Sat, 4 Dec 2004 13:19:25 +0100 (MET) Received: from smtp001.mail.ukl.yahoo.com (smtp001.mail.ukl.yahoo.com [217.12.11.32]) by nez-perce.inria.fr (8.13.0/8.13.0) with SMTP id iB4CJOV7004333 for ; Sat, 4 Dec 2004 13:19:24 +0100 Received: from unknown (HELO ?83.114.98.231?) (sejourne?kevin@83.114.98.231 with plain) by smtp001.mail.ukl.yahoo.com with SMTP; 4 Dec 2004 12:19:24 -0000 Message-ID: <41B1BAD4.2000004@yahoo.fr> Date: Sat, 04 Dec 2004 13:25:40 +0000 From: sejourne_kevin User-Agent: Mozilla Thunderbird 0.9 (X11/20041124) X-Accept-Language: en-us, en MIME-Version: 1.0 Cc: caml-list@inria.fr Subject: Re: [Caml-list] Missing a function References: <9E571848-430E-11D9-AF66-000A95CDFBE4@cs.unc.edu> <281F644B-43EF-11D9-BA22-000D9345235C@inria.fr> <6FBBD2B0-44FC-11D9-AF66-000A95CDFBE4@cs.unc.edu> <1102062166.666.25.camel@localhost> <001501c4d9f1$1b1c4600$0100a8c0@mshome.net> In-Reply-To: <001501c4d9f1$1b1c4600$0100a8c0@mshome.net> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 8bit X-Miltered: at nez-perce with ID 41B1AB4D.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Miltered: at nez-perce with ID 41B1AB4C.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; caml-list:01 gava:01 wrote:01 comparaison:01 stdlib:01 ocaml:01 hashtbl:01 functor:01 val:01 ...:98 structures:01 int:01 int:01 data:02 data:02 X-Spam-Checker-Version: SpamAssassin 3.0.0 (2004-09-13) on yquem.inria.fr X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=disabled version=3.0.0 X-Spam-Level: Frédéric Gava wrote: > Hi, > > I have done a comparaison on three data structures of the stdlib of OCaml (I > do parallel implementation of this data structure) and I find that the > module Map does not contain any function for counting the number of elements > of the data structure: > Set, cardinal: t -> int > Hashtbl, lenght : ('a,'b) t -> int > Map, you have to do "let length the_map = fold (fun _ _ i -> i+1) > the_map 0 " > > And Set and Hastbl have also fold... > > Is there an explanation (or is it just a missing ;-) ) ? There is a 'fold' function in functor Make. val fold : (key -> 'a -> 'b -> 'b) -> 'a t -> 'b -> 'b so : let cardinal e = fold (fun _ _ x -> succ x) e 0;;