当前位置: X-MOL 学术J. Funct. Program. › 论文详情
Our official English website, www.x-mol.net, welcomes your feedback! (Note: you will need to create a separate account there.)
Effect handlers via generalised continuations
Journal of Functional Programming ( IF 1.1 ) Pub Date : 2020-03-16 , DOI: 10.1017/s0956796820000040
DANIEL HILLERSTRÖM , SAM LINDLEY , ROBERT ATKEY

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.

中文翻译:

通过广义延续的效果处理程序

Plotkin 和 Pretnar 的效果处理程序为具有用户定义效果的模块化编程提供了通用抽象。本文重点介绍实现效果处理程序的基础,针对文献中提出的三种不同类型的效果处理程序:深、浅和参数化。传统的深度处理程序由计算树上的折叠定义,是 Plotkin 和 Pretnar 提出的原始构造。浅处理程序由计算树上的案例拆分(而不是折叠)定义。参数化处理程序是使用状态值扩展的深度处理程序,该状态值穿过计算树的折叠。我们根据深度处理程序直接和通过编码来制定扩展,并说明直接实现如何避免生成不必要的闭包。对于我们考虑的所有类型的处理程序,我们给出了两种不同的基本实现:一个连续传递风格(CPS)转换和一个 CEK 风格的抽象机。在这两种情况下,关键要素是对延续概念的概括,以适应效果处理程序的堆栈。我们通过以下一系列改进获得了我们的 CPS 翻译。我们从将一阶 CPS 转换为无类型 lambda 演算开始,该演算将一堆延续和处理程序作为参数的柯里化序列进行管理。然后,我们通过 uncurrying 来优化初始 CPS 翻译以产生适当的尾递归翻译,然后转向越来越多的延续的内涵表示,以支持不同类型的效果处理程序。最后,我们将翻译进行更高的排序,以便在翻译时签订行政复述。然后,我们的抽象机器设计使用与 CPS 翻译相同的广义延续表示。我们已经实现了抽象机和 CPS 转换(加上扩展)作为 Links Web 编程语言的后端。
更新日期:2020-03-16
down
wechat
bug