package yocaml

  1. Overview
  2. Docs

Effect abstraction

YOCaml is based on the user-defined-effects of OCaml 5, which makes it possible to enrich the set of effects in certain contexts (for example, tests) but also to abstract the execution context, making it possible to execute a YOCaml program via EIO (using Yocaml_eio) or even on a simple Unix source, using Yocaml_unix.

However, for the moment, the effects of OCaml are not yet tracked by the type system. For this, YOCaml uses a cheap trick described in the next section.

Eff, an IO Monad

The effects that can be propagated by YOCaml are described in the Yocaml.Eff module, which describes a function that produces effects of type 'a Eff.t. This means that any expression of type 'a Eff.t (Yocaml.Eff.t) must be interpreted (using the Yocaml.Eff.run function). The use of the direct style is lost, but thanks to the binding operators, the trade-off seems slight. So, unfortunately, we don't capture the effects that can be propagated, we simply mark a function as being able to express effects, or not.

The Eff module is described as a kind of IO monad, whose type could be summarised as type ‘a t = unit -> ’a, which is sufficient to delegate the execution of a coloured function to an OCaml effects handler (since the type is abstract).

In YOCaml, many functions return values of type 'a Yocaml.Eff.t. These are generally the different building blocks that we will use Yocaml.Eff.bind (and consort) to construct a complete YOCaml program.

Please refer to the module documentation for more information.

OCaml

Innovation. Community. Security.