module Ref: BatRef
type'a
t ='a Pervasives.ref
val ref : 'a -> 'a Pervasives.ref
val (!) : 'a Pervasives.ref -> 'a
!r
returns the current contents of reference r
.
Equivalent to fun r -> r.contents
.val (:=) : 'a Pervasives.ref -> 'a -> unit
r := 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.ref
copy 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 -> unit
swap a b
puts !b
in a
and !a
in b
val 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 toggle : bool Pervasives.ref -> unit
val oset : 'a option Pervasives.ref -> 'a -> unit
Some x
val oget_exn : 'a option Pervasives.ref -> 'a
Not_found
on oget_exn (ref None)
val print : ('b BatInnerIO.output -> 'a -> unit) ->
'b BatInnerIO.output -> 'a t -> unit
Example: IO.to_string (Ref.print Int.print) (ref 20) = "20"
val compare : 'a BatOrd.comp -> 'a Pervasives.ref BatOrd.comp
Example: let a = ref 10 and b = ref 20 in Ref.compare Int.compare a b = -1
val ord : 'a BatOrd.ord -> 'a Pervasives.ref BatOrd.ord
Example: let a = ref 10 and b = ref 20 in Ref.ord Int.ord a b = Ord.Lt
val eq : 'a BatOrd.eq -> 'a Pervasives.ref BatOrd.eq