module BatRef:Operations on references.sig..end
References are mutable values, i.e. "variables" which may actually change value during their life-time, as variables in imperative languages. References can be understood as 1-cell arrays and are typically used to implement imperative algorithms in OCaml.
References are useful but don't abuse them.
Author(s): Xavier Leroy (base module), David Teller
type'at ='a Pervasives.ref
val ref : 'a -> 'a Pervasives.refval (!) : 'a Pervasives.ref -> 'a!r returns the current contents of reference r.
Equivalent to fun r -> r.contents.val (:=) : 'a Pervasives.ref -> 'a -> unitr := a stores the value of a in reference r.
Equivalent to fun r v -> r.contents <- v.val set : 'a Pervasives.ref -> 'a -> unit := val get : 'a Pervasives.ref -> 'a ! val copy : 'a Pervasives.ref -> 'a Pervasives.refcopy r returns a new reference with the same initial
content as r.val pre : 'a Pervasives.ref -> ('a -> 'a) -> 'a
For instance, if x is a reference to 1,
pre x ( ( + ) 1) returns 2 and sets x to 2.
val post : 'a Pervasives.ref -> ('a -> 'a) -> 'a
For instance, if x is a reference to 1,
post x ( ( + ) 1) returns 1 and sets x to 2.
val swap : 'a Pervasives.ref -> 'a Pervasives.ref -> unitswap a b puts !b in a and !a in bval post_incr : int Pervasives.ref -> int
Comparable to C or Java's i++.
val post_decr : int Pervasives.ref -> int
Comparable to C or Java 's i--.
val pre_incr : int Pervasives.ref -> int
Comparable to C or Java's ++i.
val pre_decr : int Pervasives.ref -> int
Comparable to C or Java's --i.
val protect : 'a Pervasives.ref -> 'a -> (unit -> 'b) -> 'b
protect r v body sets the value of r to v and executes
body. Once body has been executed, whether termination happens
as a consequence of regular evaluation or exception, the previous
value of r is restored.
val print : (BatInnerIO.input -> 'a -> unit) -> BatInnerIO.input -> 'a t -> unit