both in ppx_let is for concurrency but the current implementation forces sequential execution.
Test
A concurrent applicative needs lazy evaluation. Since OCaml is strict the monad's type is a simple callback to the underlying type. The methods are straightforward except apply which awaits both callbacks concurrently. If its state is empty it stores the underlying value otherwise it applies both for the listener. bind's tests expect callbacks to execute sequentially while the both's verify concurrency.
Implementation
Adds apply_both to the Apply type class. It seemed perfect because of its symmetry to apply_first. Formally both is the Monoidal equivalent of apply (commonly called merge). I thought both would need pure for lifted map but it worked without it. I also considered supplying overrides but it's tricky to implement lawfully.
both
inppx_let
is for concurrency but the current implementation forces sequential execution.Test
A concurrent applicative needs lazy evaluation. Since OCaml is strict the monad's type is a simple callback to the underlying type. The methods are straightforward except
apply
which awaits both callbacks concurrently. If its state is empty it stores the underlying value otherwise it applies both for the listener.bind
's tests expect callbacks to execute sequentially while theboth
's verify concurrency.Implementation
Adds
apply_both
to theApply
type class. It seemed perfect because of its symmetry toapply_first
. Formallyboth
is theMonoidal
equivalent ofapply
(commonly calledmerge
). I thoughtboth
would needpure
for liftedmap
but it worked without it. I also considered supplying overrides but it's tricky to implement lawfully.