A mutable variable whose state can be watched as a Tenacious computation.
'a Var.t
is conceptually a 'a Ref.t
with
Var.{create,get,set,replace}
corresponding to
Ref.{create,(!),(:=),replace}
.
The important difference is the watch
function, that lets you construct tenacious
computations that depend on the value of the variable.
val create : 'a ‑> 'a t
val set : 'a t ‑> 'a ‑> unit
Set new value for the variable.
Any hearts derived from watch
are broken immediately.
val get : 'a t ‑> 'a
Get the current value of the variable without watching it.
Should be avoided in Tenacious computations.
Use watch
instead.
val replace : 'a t ‑> f:('a ‑> 'a) ‑> unit