Hostname: page-component-6766d58669-kn6lq Total loading time: 0 Render date: 2026-05-25T02:35:19.636Z Has data issue: false hasContentIssue false

Effect handlers via generalised continuations

Published online by Cambridge University Press:  16 March 2020

DANIEL HILLERSTRÖM
Affiliation:
Laboratory for Foundations of Computer Science, The University of Edinburgh, EdinburghEH8 9YL, UK, (e-mail: daniel.hillerstrom@ed.ac.uk)
SAM LINDLEY
Affiliation:
Laboratory for Foundations of Computer Science, The University of Edinburgh, EdinburghEH8 9YL, UK Department of Computing, Imperial College London, LondonSW7 2BU, UK, (e-mail: sam.lindley@ed.ac.uk)
ROBERT ATKEY
Affiliation:
Mathematically Structured Programming Group, University of Strathclyde, GlasgowG1 1XQ, UK, (e-mail: robert.atkey@strath.ac.uk)
Rights & Permissions [Opens in a new window]

Abstract

Core share and HTML view are not available for this content. However, as you have access to this content, a full PDF is available via the 'Save PDF' action button.

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.

Information

Type
Research Article
Copyright
© The Author(s) 2020. Published by Cambridge University Press
Submit a response

Discussions

No Discussions have been published for this article.