Risto-Stevcev / bastet

A ReasonML/Ocaml library for category theory and abstract algebra
BSD 3-Clause "New" or "Revised" License
211 stars 26 forks source link

Bugfix/applicative both (fixes #3) #6

Closed texastoland closed 6 years ago

texastoland commented 6 years ago

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.

Risto-Stevcev commented 6 years ago

Nice! thanks for the PR :slightly_smiling_face: