Module Counter (.ml)


module Counter: sig .. end
int counter

a counter for non-negative numbers.



Types

type counter 
exception OVERFLOW
raised if the counter is exhausted.

Functions

val create : unit -> counter
creates a fresh counter initialized with 0.
val create_with : int -> counter
create_with start_value creates a new counter with start_value. start_value must be >= 0.
val set : counter -> int -> unit
set value sets the counter to value. value must be >= 0.
val inc : counter -> unit
increments the counter by 1.
Raises OVERFLOW on overflow.
val inc_by : counter -> int -> unit
increments the counter by the given positive value.
Raises OVERFLOW on overflow.
val dec : counter -> unit
decrements the counter by 1.
Raises OVERFLOW if the counter drops below 0.
val next : counter -> int
increments the counter by 1 and returns its new value. Note: this implies that 0 is never returned as a counter value.
Raises OVERFLOW on overflow.
val value : counter -> int
returns the current value of the counter.