Algebraic effects & handlers have become a standard approach for side-effects in functional programming. Their modular composition with other effects and clean separation of syntax and semantics make them attractive to a wide audience. However, not all effects can be classified as algebraic; some need a more sophisticated handling. In particular, effects that have or create a delimited scope need special care, as their continuation consists of two parts-in and out of the scope-and their modular composition introduces additional complexity. These effects are called scoped and have gained attention by their growing applicability and adoption in popular libraries. While calculi have been designed with algebraic effects & handlers built in to facilitate their use, a calculus that supports scoped effects & handlers in a similar manner does not yet exist. This work fills this gap: we present $\lambda_{\mathit{sc}}$, a calculus with native support for both algebraic and scoped effects & handlers. It addresses the need for polymorphic handlers and explicit clauses for forwarding unknown scoped operations to other handlers. Our calculus is based on Eff, an existing calculus for algebraic effects, extended with Koka-style row polymorphism, and consists of a formal grammar, operational semantics, a (type-safe) type-and-effect system and type inference. We demonstrate $\lambda_{\mathit{sc}}$ on a range of examples.
翻译:代数效应和处理已成为函数式编程中用于处理副作用的标准方法。它们与其他效应的模块化组合以及语法和语义的清晰分离使它们受到广泛关注。然而,并非所有效应都可以归类为代数效应;有些需求更为复杂的处理方式。特别是,具有或创建了有界范围的效应需要特殊处理,因为它们的 continuation 由两部分组成——进入范围和出范围——在模块化组合中引入了额外的复杂性。这些效应被称为作用域性,它们由于其广泛的适用性和流行库中的采用而逐渐受到关注。虽然已经设计出了支持代数效应和处理的微积分以方便使用,但目前还不存在一种与之类似支持作用域效应和处理的微积分。本文填补了这一空白:我们提出 $\lambda_{\mathit{sc}}$,一种具有本地支持代数和作用域效应和处理的微积分。它解决了多态处理程序的需求和将未知的作用域操作转发到其他处理程序的显式子句。我们的微积分基于 Eff(一种已存在的用于代数效应的微积分),扩展了 Koka 风格的行多态性,并包括正式语法、操作语义、(类型安全的)类型和效应系统以及类型推断。我们在一系列示例中展示了 $\lambda_{\mathit{sc}}$。