module Count:sig..end
Example: consider this function that makes a set from a list of integers:
foldl (flip S.add) S.empty
Suppose we want to convert the function to also count the number of ints we've added; with the Count module we just need to change the function definition to:
foldl (Count.update (flip S.add)) (Count.init S.empty)
In other words, we just initialize our initial accumulator using Count.init,
and then apply the Count.update combinator to our folding function.
Warning! Documentation bug: type t is actually abstract!
type'at =int * 'a
val init : ?i:int -> 'a -> int * 'ainit ?i a: convert initial accumulator value a to a counting accumulatori : initial value for counta : initial accumulatorval n : 'a * 'b -> 'an ca: extract count from counting accumulator caval acc : 'a * 'b -> 'bacc ca: extract accumulator from counting accumulator caval pair : 'a -> 'apair ca: extract count and accumulator as a pairval update : ?i:int -> ('a -> 'b -> 'c) -> int * 'a -> 'b -> int * 'cupdate ?i f ca: return updated counting accumulator ca by applying f
to ca and incrementing the count by i (default: 1)val incr : ?i:int -> int * 'a -> int * 'aincr ?i ca: return counting accumulator ca with count incremented by i
(default: 1) but with accumulator unmodifiedval withcount : ('a -> 'b) -> 'a * 'c -> 'cwithcount f ca: apply f to the count in ca (for side-effect, e.g. printing),
returning the accumulator