package timed

  1. Overview
  2. Docs
Timed references for imperative state

Install

Dune Dependency

Authors

Maintainers

Sources

1.1.tar.gz
md5=06106626006450f41f0c4d4fcbcf95d0
sha512=b136d79e6ad1a50c811acadc0ae0be049f2dc0d6fc87d233400d602cdf8c6dab3af87557e8f8d740f6eba4b87b9d5b2fcc7e550d24e4ba8c03237573da5623d5

doc/timed.compat/Timed_compat/index.html

Module Timed_compatSource

Timed references for Stdlib.ref. This module redefines the all the functions used to update references, and enables the restoration of saved reference states.

  • author Christophe Raffalli
  • author Rodolphe Lepigre

Note that this module allocates one blocks of memory at initialization for its internal state. It occupies a total of four words.

Sourceval (:=) : 'a ref -> 'a -> unit

r := v sets the value of the reference r to v. This operation has a very small overhead compared to Stdlib.((:=)) if no time has been via Time.save. Nonetheless, it is always constant time, and allocation is only necessary if the current “time” is accessible (or not reclaimed by the garbage-collector). When that is the case, three blocks of memory are allocated, for a total of eight words.

Sourceval incr : int ref -> unit

incr r is equivalent to r := !r + 1.

Sourceval decr : int ref -> unit

decr r is equivalent to r := !r - 1.

Sourcemodule Time : sig ... end

The Time module provides an abstract representation of time, used to set a point from which (monitored) updates to references are recorded to allow undoing/redoing the corresponding changes.

Sourceval pure_apply : ('a -> 'b) -> 'a -> 'b

pure_apply f v computes the result of f v, but reverts the (monitored) updates made to references in the process before returning the value.

Sourceval pure_test : ('a -> bool) -> 'a -> bool

pure_test p v applies the predicate p to v (i.e., compute p v) and returns the result, reverting (monitored) updates made to reference if the result is false. Updates are preserved if the result is true.

OCaml

Innovation. Community. Security.