Effects handlers usage investigation
Context
With the upcoming OCaml V5 comes the long-awaited effect handlers. Effect handlers have been all the rage these last years in Haskell world, some languages like Unison even building them in their language directly.
Objective
We propose to explore using effect handlers in Tezos both to replace existing monads that are subsumed by effects handlers:
- the Error monad,
- the Lwt monad,
- the combined Lwt/Error monad
but also to support effects that are currently hand-crafted/manually coded/coupled, e.g.:
- the monad for reading/writing Context.t (which would be the State monad in Haskell terms),
- the readonly Context.t monad (the Reader monad).
- the logging monad (events in Tezos terms)
An additional benefit of effect handlers is that they simplify testability: a business function could have the effects "Logging, State Context, Error" and a test could easily "mock" how these effects behave inside the test (by simply changing the effect handler). Here's an example in Haskell but the idea would be the same.
Success criterion
This project is concerned with practical integration of effects handlers within the tezos/tezos codebase. The project will be a success if one of these criterion is met:
- One or more packages are modified to use effects handlers, hereby showing by example what it means to use them and what it implies in terms of code readibility.
- Reasons why using effects handlers in tezos/tezos is impossible and/or impractical. For example, because the use is too heavyweight. In this case, we expect pointers to possible improvements to effects handlers - that would change this outcome - to have been explored and documented.