Lune

PLDI2021Top-tier venue

Retrofitting effect handlers onto OCaml

K. C. Sivaramakrishnan, Stephen Dolan, Leo White, Tom Kelly, Sadiq Jaffer, Anil Madhavapeddy

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. 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 nonlocal 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.

Ask Lune

Know this paper in minutes, not an afternoon.

Lune can read every page of it and the top-tier papers that cite it, and gives you its claims, its evidence and its limits, each one cited to the paper it comes from. No skimming, no AI slop.

25 top-tier papers have cited it since. Know what they found before your reviewers do.

Questions to start from

Lune can draw on

the full paper · the top-tier papers that cite it · related work

Get the answer

Free to start. No credit card required.

Lineage

  • Reachability types: tracking aliasing and separation in higher-order functional programs cites Binders by day, labels by night: effect instances via lexically scoped handlers
  • Continuing WebAssembly with Effect Handlers cites Compiler and runtime support for continuation marks
  • Continuing WebAssembly with Effect Handlers cites High-level effect handlers in C++
  • Continuing WebAssembly with Effect Handlers cites From folklore to fact: comparing implementations of stacks and continuations
  • Answer Refinement Modification: Refinement Type System for Algebraic Effects and Handlers cites Binders by day, labels by night: effect instances via lexically scoped handlers
  • High-level effect handlers in C++ cites Binders by day, labels by night: effect instances via lexically scoped handlers
  • Soundly Handling Linearity cites Continuing WebAssembly with Effect Handlers
  • Soundly Handling Linearity cites High-level effect handlers in C++
  • Soundly Handling Linearity cites Binders by day, labels by night: effect instances via lexically scoped handlers
Builds onCited byLeft to right by year; the more cited, the higher.

Cited by top-tier papers25

  1. Continuing WebAssembly with Effect HandlersLuna Phipps-Costin, Andreas Rossberg, Arjun Guha, Daan Leijen et al.OOPSLA 2023 · 20 citations
  2. Reachability types: tracking aliasing and separation in higher-order functional programsYuyan Bao, Guannan Wei, Oliver Bracevac, Yuxuan Jiang et al.OOPSLA 2021 · 19 citations
  3. High-level effect handlers in C++Dan R. Ghica, Sam Lindley, Marcos Maroñas Bravo, Maciej PirógOOPSLA 2022 · 14 citations
  4. Answer Refinement Modification: Refinement Type System for Algebraic Effects and HandlersFuga Kawamata, Hiroshi Unno, Taro Sekiyama, Tachio TerauchiPOPL 2024 · 8 citations
  5. Soundly Handling LinearityWenhao Tang, Daniel Hillerström, Sam Lindley, J. Garrett MorrisPOPL 2024 · 8 citations

Builds on3

  1. Binders by day, labels by night: effect instances via lexically scoped handlersDariusz Biernacki, Maciej Piróg, Piotr Polesiuk, Filip SieczkowskiPOPL 2020 · 46 citations
  2. From folklore to fact: comparing implementations of stacks and continuationsKavon Farvardin, John H. ReppyPLDI 2020 · 17 citations
  3. Compiler and runtime support for continuation marksMatthew Flatt, R. Kent DybvigPLDI 2020 · 9 citations

Related papers

  1. Efficient compilation of algebraic effect handlersGeorgios Karachalias, Filip Koprivec, Matija Pretnar, Tom SchrijversOOPSLA 2021 · 9 citations
  2. Tracing Just-in-Time Compilation for Effects and HandlersMarcial Gaißert, Carl Friedrich Bolz-Tereick, Jonathan Immanuel BrachthäuserOOPSLA 2025
  3. Dynamic Wind for Effect HandlersDavid Voigt, Philipp Schuster, Jonathan Immanuel BrachthäuserOOPSLA 2025
  4. Handling bidirectional control flowYizhou Zhang, Guido Salvaneschi, Andrew C. MyersOOPSLA 2020 · 12 citations
  5. Affect: An Affine Type and Effect SystemOrpheas van Rooij, Robbert KrebbersPOPL 2025 · 7 citations
Dusk over the sea between two cliffs drawn in fine vertical lines