Continuation Passing Style for Effect Handlers

Daniel Hillerström, Sam Lindley, Robert Atkey, K. C. Sivaramakrishnan, Marc Herbstritt
2017 International Conference on Rewriting Techniques and Applications  
We present Continuation Passing Style (CPS) translations for Plotkin and Pretnar's effect handlers with Hillerström and Lindley's row-typed fine-grain call-by-value calculus of effect handlers as the source language. CPS translations of handlers are interesting theoretically, to explain the semantics of handlers, and also offer a practical implementation technique that does not require special support in the target language's runtime. We begin with a first-order CPS translation into untyped
more » ... da calculus which manages a stack of continuations and handlers as a curried sequence of arguments. We then refine the initial CPS translation first by uncurrying it to yield a properly tail-recursive translation and second by making it higher-order in order to contract administrative redexes at translation time. We prove that the higher-order CPS translation simulates effect handler reduction. We have implemented the higher-order CPS translation as a JavaScript backend for the Links programming language. Algebraic effects, introduced by Plotkin and Power [25], and their handlers, introduced by Plotkin and Pretnar [26] , provide a modular foundation for effectful programming. Though originally studied in a theoretical setting, effect handlers are also of practical interest, as witnessed by a range of recent implementations [2, 4, 8, 11, 13, 15, 17, 20] . Notably, the Multicore OCaml project brings effect handlers to the OCaml programming language as a means for abstracting over different scheduling strategies [8] . As a programming abstraction, effect handlers can be viewed as a more modular alternative to monads [23, 29] . An algebraic effect is a signature of operations along with an equational theory on those operations. An effect handler is a delimited control operator which interprets a particular subset of the signature of operations up to equivalences demanded by the equational theory. In practice current implementations do not support equations on operations, and as such, the underlying algebra is the free algebra, allowing handlers maximal interpretative freedom. Correspondingly, in this paper we assume free algebras for effects.
doi:10.4230/lipics.fscd.2017.18 dblp:conf/rta/HillerstromLAS17 fatcat:qlusgstq6ngqvnryhxpwtmfkae