The language Eff is an OCaml-like language serving as a prototype implementation of the theory of algebraic effects, intended for experimentation with algebraic effects on a large scale.We present the embedding of Eff into OCaml, using the library of delimited continuations or the multicore OCaml branch. We demonstrate the correctness of the embedding denotationally, relying on the tagless-final-style interpreter-based denotational semantics, including the novel, direct denotational semantics of multi-prompt delimited control. The embedding is systematic, lightweight, performant and supports even higher-order, 'dynamic' effects with their polymorphism. OCaml thus may be regarded as another implementation of Eff, broadening the scope and appeal of that language. 1 https://github.com/atnos-org/eff, https://github.com/m50d/paperdoll, among others 2 https://www.humblespark.com/blog/extensible-effects-in-node-part-1 3 http://purescript.org 4 http://www.eff-lang.org/ 5 While writing this paper we have implemented delimited control in yet another way, in pure OCaml: see Core delimcc in §3.2. Although developed for the formalization of the Eff translation, it may be used in real programs -provided the code is written in a particular stylized way as shown in §3.2. In contrast, the original delimcc and Multicore OCaml can be used with the existing OCaml code as it is. Hence they let Eff be embedded rather than compiled into OCaml.
24Eff Directly in OCaml detail in §3.1.4). We also demonstrate the novel denotational semantics of multi-prompt delimited control that does not rely on continuation-passing-style (and is, hence, direct).The structure of the paper is as follows. First we informally introduce Eff on a simple example. §2.2 then demonstrates our translation to OCaml using the delimcc library, putting Eff and the corresponding OCaml code side-by-side. §2.3 shows how the embedding works in multicore OCaml with its 'native effects'. §3 gives the formal, denotational treatment, reminding the denotational semantics of Eff; describing the novel direct denotational semantics of multi-prompt delimited control; then presenting the translation precisely; and arguing that it is meaning-preserving. We describe the translation of the dynamic effects into OCaml in §4. The empirical §5 evaluates the performance of our implementation of Eff comparing it with the Eff's own optimizing compiler. Related work is reviewed in §6. We then conclude and summarize the research program inspired by our Eff embedding.The source code of all our examples and benchmarks is available at http://okmij.org/ftp/ continuations/Eff/.
Eff in Itself and OCamlWe illustrate the Eff embedding on the running example, juxtaposing the Eff code with the corresponding OCaml. We thus demonstrate both the simplicity of the translation and the way to do Eff-like effects in idiomatic OCaml.
A taste of EffAn effect in Eff has to be declared first 6 : type α nondet = effect operation fail : unit → empty operation choose : (α * α) → α end Our running effect is thus famili...