Retrofitting Effect Handlers onto OCaml

KC Sivaramakrishnan, Stephen Dolan, Leo White, Tom Kelly, Sadiq Jaffer +1 more
4/1/2021
86 citations
cs.PL

Official code: ocaml-multicore/ocaml-multicore (762 stars, OCaml, last commit 2022-12-09). 1 more implementation below.

Abstract

Effect handlers have been gathering momentum as a mechanism for modular programming with user-defined effects. Effect handlers allow for non-local control flow mechanisms such as generators, async/await, lightweight threads and coroutines to be composably expressed.

Show full abstract

We present a design and evaluate a full-fledged efficient implementation of effect handlers for OCaml, an industrial-strength multi-paradigm programming language. Our implementation strives to maintain the backwards compatibility and performance profile of existing OCaml code. Retrofitting effect handlers onto OCaml is challenging since OCaml does not currently have any non-local control flow mechanisms other than exceptions. Our implementation of effect handlers for OCaml: (i) imposes a mean 1% overhead on a comprehensive macro benchmark suite that does not use effect handlers; (ii) remains compatible with program analysis tools that inspect the stack; and (iii) is efficient for new code that makes use of effect handlers.

View on arXivView PDF

Code Implementations(2)

Code implementations of this paper
RepositoryTypeStarsLanguageLicenseLast commit
ocaml-multicore/ocaml-multicoreOfficial762OCaml–2022-12-09
ocaml-multicore/effects-examplesOfficial454OCamlISC2026-03-20

Multicore OCaml

76271OCaml, CApr 24, 20153 years agoNOASSERTION
algebraic-effectsconcurrencyhandlersmulticoreocaml
ISC

Examples to illustrate the use of algebraic effects in Multicore OCaml

45436OCaml, HaskellMay 20, 20158 months agoISC

Similar Papers

Cite this paper

@article{sivaramakrishnan2021retrofitting,
  title  = {Retrofitting Effect Handlers onto OCaml},
  author = {KC Sivaramakrishnan and Stephen Dolan and Leo White and Tom Kelly and Sadiq Jaffer and Anil Madhavapeddy},
  year   = {2021},
  eprint = {2104.00250},
  archivePrefix = {arXiv},
  url    = {https://arxiv.org/abs/2104.00250}
}

Add a badge to your README

Shows whether official code is linked for this paper.

Code of Paper badge
[![Code of Paper](https://codeofpaper.com/badge/2104.00250.svg)](https://codeofpaper.com/paper/2104.00250)

Discussion