package current_incr
Install
Dune Dependency
Authors
Maintainers
Sources
sha256=86648df3a0940369830f819aa0049d09a6c4f642278cf6d38cd87fcca0f95cc1
sha512=7e30d310897bc4d067b4021c9453b74d505db5c5d8c429254da238faa40f93da4370a11f7e29973371baca3fa8d55693a052bf4679018ca97bc4aa0cfb11fec6
doc/current_incr/Current_incr/index.html
Module Current_incr
Source
A simple library for incremental computations. Based on "Adaptive Functional Programming" https://www.cs.cmu.edu/~guyb/papers/popl02.pdf
The basic idea is:
- You run a computation, which produces a result.
- The library records information about the dependencies of the result.
- You can then change one or more inputs and it will rerun just the parts of the computation that are needed to update the result.
It is similar to Jane Street's "incremental" library, but much smaller and has no external dependencies.
It is also similar to "react", but the results do not depend on the behaviour of the garbage collector. In particular, functions stop being called as soon as they are no longer needed, and cannot be called with "impossible" inputs.
Changeable values
An 'a t
holds a value of type 'a
, which will update as necessary.
Changeable computations
An 'a cc
is a changeable computation that can be run to get a value of type 'a
. Internally, it is a function that takes a destination variable, reads zero or more other changeable values, and then updates the destination.
read x f
is a computation that depends on x
. f
will be called as necessary to ensure that the result stays up-to-date with changes in x
.
write x
is a computation that always returns x
.
on_release fn
calls fn
if the current computation has to be redone. This may be useful to release external resources when they are no longer needed. Note that the order in which multiple such functions are called is somewhat unpredictable.
A convenience function to read a value, apply a function to it, and write the result.
External operations
These functions are used to interface between the changeable system and other systems (e.g. Lwt).
A mutable value that can be changed using change
. Internally, type 'a var = 'a t
, but it's useful to distinguish between values that are inputs to the system and values that only change in response to computations being rerun.
change x v
sets the current value of x
to v
and adds anything that depends on it to the rebuild queue. You must call propagate
after this to update everything (you can change several things together and then call propagate
once). This function can only be used from the top-level, not from within a computation.
Apply all changes made with change
, so that everything is up-to-date.