Browse thread
Strange observation on polymorphic '<'
[
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: | 2004-12-04 (12:19) |
From: | sejourne_kevin <sejourne_kevin@y...> |
Subject: | Re: [Caml-list] Missing a function |
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;;