package bonsai

  1. Overview
  2. Docs
Legend:
Library
Module
Module type
Parameter
Class
Class type

The Memo module can be used to share a computation between multiple components, meaning that if the shared computation is stateful, then the users of that computation will see the same state.

The way that Memo differs from just using let%sub on a computation and then passing the resulting Value.t down to its children is twofold:

  • The shared computation is not made active until it's actually requested by another component
  • Knowledge of any inputs to component are be deferred to "lookup time", when components request an instance of the component.

Shared computations are refcounted, so when the last user of a memoized component deactivates, the shared component is deactivated as well.

type ('input, 'result) t
val create : ('input, 'cmp) comparator -> f:('input Value.t -> 'result Computation.t) -> ('input, 'result) t Computation.t

Creates a memo instance that can be used by calling lookup

val lookup : (module Model with type t = 'input) -> ('input, 'result) t Value.t -> 'input Value.t -> 'result option Computation.t

Requests an instance of the shared computation for a given 'input value. If an instance doesn't already exist, it will request a new computation, which results in none being returned for a brief period of time, after which it'll return a Some containing the result of that computation

OCaml

Innovation. Community. Security.