Reference. Continuation Passing Style for Effect Handlers

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

Cite

Cite as @hillerstrom-2017-continuation (helia, typst) · \cite{hillerstrom-2017-continuation} (LaTeX)
BibTeX
bibtex · 14 lines
@inproceedings{hillerstrom-2017-continuation,
  doi = {10.4230/LIPICS.FSCD.2017.18},
  url = {https://drops.dagstuhl.de/entities/document/10.4230/LIPIcs.FSCD.2017.18},
  author = {Hillerström, Daniel and Lindley, Sam and Atkey, Robert and Sivaramakrishnan, K. C.},
  keywords = {effect handlers, delimited control, continuation passing style},
  language = {en},
  title = {Continuation Passing Style for Effect Handlers},
  volume = {84},
  pages = {18:1-18:19},
  publisher = {Schloss Dagstuhl – Leibniz-Zentrum für Informatik},
  year = {2017},
  copyright = {Creative Commons Attribution 3.0 Unported license},
  booktitle = {2nd International Conference on Formal Structures for Computation and Deduction (FSCD 2017)}
}
hayagriva YAML (typst)
yaml · 18 lines
hillerstrom-2017-continuation:
  type: article
  title: Continuation Passing Style for Effect Handlers
  author:
  - Hillerström, Daniel
  - Lindley, Sam
  - Atkey, Robert
  - Sivaramakrishnan, K. C.
  date: 2017
  page-range: 18:1-18:19
  url: https://drops.dagstuhl.de/entities/document/10.4230/LIPIcs.FSCD.2017.18
  serial-number:
    doi: 10.4230/LIPICS.FSCD.2017.18
  parent:
    type: proceedings
    title: 2nd International Conference on Formal Structures for Computation and Deduction (FSCD 2017)
    publisher: Schloss Dagstuhl – Leibniz-Zentrum für Informatik
    volume: 84
Cited by (2)

Effect handlers via generalised continuations hillerstrom-2020-effect

Plotkin and Pretnar’s effect handlers offer a versatile abstraction for modular programming with user-defined effects. This paper focuses on foundations for implementing effect handlers, for the three different kinds of effect handlers that have been proposed in the literature: deep, shallow, and parameterised. Traditional deep handlers are defined by folds over computation trees and are the original construct proposed by Plotkin and Pretnar. Shallow handlers are defined by case splits (rather than folds) over computation trees. Parameterised handlers are deep handlers extended with a state value that is threaded through the folds over computation trees. We formulate the extensions both directly and via encodings in terms of deep handlers and illustrate how the direct implementations avoid the generation of unnecessary closures. We give two distinct foundational implementations of all the kinds of handlers we consider: a continuation-passing style (CPS) transformation and a CEK-style abstract machine. In both cases, the key ingredient is a generalisation of the notion of continuation to accommodate stacks of effect handlers. We obtain our CPS translation through a series of refinements as follows. We begin with a first-order CPS translation into untyped lambda calculus which manages a stack of continuations and handlers as a curried sequence of arguments. We then refine the initial CPS translation by uncurrying it to yield a properly tail-recursive translation and then moving towards more and more intensional representations of continuations in order to support different kinds of effect handlers. Finally, we make the translation higher order in order to contract administrative redexes at translation time. Our abstract machine design then uses the same generalised continuation representation as the CPS translation. We have implemented both the abstract machine and the CPS transformation (plus extensions) as backends for the Links web programming language.
PDF · DOI · pldb

On the expressive power of user-defined effects: Effect handlers, monadic reflection, delimited control forster-2019-on

We compare the expressive power of three programming abstractions for user-defined computational effects: Plotkin and Pretnar’s effect handlers, Filinski’s monadic reflection, and delimited control. This comparison allows a precise discussion about the relative expressiveness of each programming abstraction. It also demonstrates the sensitivity of the relative expressiveness of user-defined effects to seemingly orthogonal language features. We present three calculi, one per abstraction, extending Levy’s call-by-push-value. For each calculus, we present syntax, operational semantics, a natural type-and-effect system, and, for effect handlers and monadic reflection, a set-theoretic denotational semantics. We establish their basic metatheoretic properties: safety, termination, and, where applicable, soundness and adequacy. Using Felleisen’s notion of a macro translation, we show that these abstractions can macro express each other, and show which translations preserve typeability. We use the adequate finitary set-theoretic denotational semantics for the monadic calculus to show that effect handlers cannot be macro expressed while preserving typeability either by monadic reflection or by delimited control. Our argument fails with simple changes to the type system such as polymorphism and inductive types. We supplement our development with a mechanised Abella formalisation.
PDF · DOI · pldb
Cites 27 works (2 here)
With notes (2)

Do be do be do lindley-2017-do

PDF · DOI · arXiv · pldb

Handlers in action kammar-2013-handlers

PDF · DOI · pldb
External (25)
  • On the expressive power of user-defined effects: Effect handlers, monadic reflection, delimited control (2017)
  • Type directed compilation of row-typed algebraic effects (2017)
  • Liberating effects with rows and handlers (2016)
  • Eff directly in OCaml (2016)
  • Programming with algebraic effects and handlers (2015)
  • Effective concurrency through algebraic effects (2015)
  • Freer monads, more extensible effects (2015)
  • An introduction to algebraic effects and handlers (2015)
  • Programming and reasoning with algebraic effects and dependent types (2013)
  • Handling algebraic effects (2013)
  • Row-based effect types for database integration (2012)
  • A dynamic interpretation of the CPS hierarchy (2012)
  • Subtyping delimited continuations (2011)
  • Compiling with continuations, continued (2007)
  • Links: Web programming without tiers (2006)
  • A first-order one-pass CPS transformation (2003)
  • Modelling environments in call-by-value programming languages (2003)
  • Adequacy for algebraic effects (2001)
  • A calculus of tagged types, with applications to process languages (1995)
  • The essence of compiling with continuations (1993)
  • Syntactic theories and the algebra of record terms (1993)
  • Compiling with Continuations (1992)
  • The essence of functional programming (1992)
  • Notions of computation and monads (1991)
  • Call-by-name, call-by-value and the lambda-calculus (1975)
hillerstrom-2017-continuation reference entries/refs/hillerstrom-2017-continuation/hillerstrom-2017-continuation.hel