The
type 'asaref
The type of a single-assignment reference. It is similar to the standard
exception Locked
This exception is raised if an attempt is made to assign a value twice to the same reference.
val saref : unit -> 'a saref
Construct a single-assignment reference.
val saset : 'a saref * 'a -> unit
Assign a value to the reference. If it has already been assigned a value
this will raise
val savalue : 'a saref -> 'a option
Extract the current value of the reference. If it has not yet been assigned
a value it will return
The reason behind the
Because of these differences mutable data has to be handled separately from
immutable data by the garbage collector. Using mutable cells imposes an extra
cost on each collection when compared with immutable data. In addition it is
possible to reduce the heap size by merging immutable cells that have the same
contents. In some circumstances the garbage collector may do this automatically;
more often it is done explicitly using
The
A typical use for a single-assignment reference is when a data structure is
being built by multiple threads. A