Bonsai_proc.Computationtype 'a t = Cont.graph @ local -> 'a Cont.tA value of type 'a Computation.t represents a computation which produces a value that may change during the lifetime of a program, and the value may be influenced by the internal state of that computation.
The same 'a Computation.t can be used in multiple places in a program, and these uses will not share the same state, nor will they share the work performed by the computation.
In this normal OCaml code, if we see the same function being called multiple times:
let a = f () in
let b = f () in
a + bYou would not be surprised to know that if f has side-effects (maybe printing to the console), then those side-effects happen twice because f was called twice.
Similarly, if we wrote the code this way:
let a = f () in
let b = a in
a + bYou would (correctly) expect that the side-effect only happens once, when computing a. In these examples, the code f () is analogous to _ Computation.t. If you want to have two separate values whose computations maintain separate state, you would use two instances of "let%sub" to bind them separately:
val some_computation : int Computation.t
val add : int Value.t -> int Value.t -> int Computation.t
let open Let_syntax in
let%sub a = some_computation in
let%sub b = some_computation in
add a bHere, a and b can take on different values depending on the states of the computations that produce them.
However, if you want to use just one value in multiple places, only use let%sub once:
let open Let_syntax in
let%sub a = some_computation in
let b = a in
add a bHere, a and b always take on the same value.
include Bonsai_private_base.Applicative.S with type 'a t := 'a tval return : here:lexing_position -> 'a -> 'a tmodule Applicative_infix : sig ... endval all_map :
here:lexing_position ->
('k, 'v t, 'cmp) Core.Map.t ->
('k, 'v, 'cmp) Core.Map.t tSimilar to all which pulls the computation outside of a list, all_map does the same, but with the data in a map. This can be a useful replacement for assoc in scenarios where the map is a constant size.
The analog of List.reduce_balanced for computations, but with f operating on values instead of the computations themselves
module Let_syntax : sig ... end