Legend:
Library
Module
Module type
Parameter
Class
Class type
Library
Module
Module type
Parameter
Class
Class type
This module offers mutable stores based on mutable transactional references. These stores support a simple form of transactions that can be either aborted or committed. Transactions cannot be nested.
A store can be thought of as a region of memory in which objects, known as references, can be dynamically allocated, read, and written. Stores are homogeneous: all references in a store of type 'a store
have the content type, namely 'a
. In general, a store may be persistent or mutable, depending on which data structure is used to implement it.
val new_store : unit -> 'a store
new_store()
creates an empty store.
A reference of type 'a rref
can be thought of as (a pointer to) an object that exists in some store.
make s v
creates a fresh reference in the store s
and sets its content to v
. It returns a pair of an updated store and the newly-created reference.
get s x
reads the current content of the reference x
in the store s
. It returns a pair of a possibly-updated store and the current content of the reference.
set s x v
updates the store s
so as to set the content of the reference x
to v
. It returns an updated store.
eq s x y
determines whether the references x
and y
are the same reference. It returns a pair of a possibly-updated store and a Boolean result. The references x
and y
must belong to the store s
.
val tentatively : 'a store -> (unit -> 'b) -> 'b
tentatively s f
runs the function f
within a new transaction on the store s
. If f
raises an exception, then the transaction is aborted, and all updates performed by f
on references in the store s
are rolled back. If f
terminates normally, then the updates performed by f
are committed.
Two transactions on a single store cannot be nested.
A cell that is created during a transaction still exists after the transaction, even if the transaction is rolled back. In that case, its content should be considered undefined.