Algebraic effects offer a versatile framework that covers a wide variety of effects. However, the family of operations that delimit scopes are not algebraic and are usually modelled as handlers, thus preventing them from being used freely in conjunction with algebraic operations. Although proposals for scoped operations exist, they are either ad-hoc and unprincipled, or too inconvenient for practical programming. This paper provides the best of both worlds: a theoretically-founded model of scoped effects that is convenient for implementation and reasoning. Our new model is based on an adjunction between a locally finitely presentable category and a category of functorial algebras. Using comparison functors between adjunctions, we show that our new model, an existing indexed model, and a third approach that simulates scoped operations in terms of algebraic ones have equal expressivity for handling scoped operations. We consider our new model to be the sweet spot between ease of implementation and structuredness. Additionally, our approach automatically induces fusion laws of handlers of scoped effects, which are useful for reasoning and optimisation.
翻译:代数效应提供了一个涵盖广泛各种效应的多功能框架。然而,划定范围的操作组合不是代数效应,通常仿照操作者,因此无法与代数操作自由使用。虽然有关于范围操作的建议,但它们不是临时的,就是没有原则的,或太不方便实用的编程。本文提供了两个世界的最好条件:一个理论上的、便于执行和推理的、范围效应模型。我们的新模型基于一个局部有限现成类别和复古代数类别之间的配套法。我们利用对辅助作用进行比较,我们展示了我们的新模型、一种现有的指数模型和一种模拟变形操作的第三个方法对于处理范围操作具有同等的直观性。我们认为,我们的新模型是易于执行和结构化之间的温和点。此外,我们的方法会自动产生范围效应处理者的聚合法,这对推理和优化有用。