一句话:把代数效应与处理器从 monad 推广到广义幺半,统一 monad、applicative 与 arrow 并支持处理器复用。
传统代数效应与处理器基于 monad 组织效应,但许多副作用并非 monad 式。本文将效应与处理器从 monad 推广到广义幺半,把范畴论基础从自由代数改为自由幺半,从而统一 monad、applicative functor 与 arrow 等计算类。作者进一步用 lax monoidal functor 支持处理器和程序跨计算类复用,例如以 monadic 处理器处理 applicative 计算。文中以构建系统为主要用例,把任务视为自由计算并由处理器解释。该工作扩展了处理器接口的适用范围,评估以理论构造和构建系统示例为主。
Abstract Algebraic effects and handlers are a convenient method for structuring monadic effects with primitive effectful operations and separating the syntax from the interpretation of these operations. However, the scope of conventional handlers is limited as not all side effects are monadic in nature. This paper generalizes the notion of algebraic effects and handlers from monads to generalized monoids, which notably covers applicative functors and arrows as well as monads. For this purpose, we switch the category theoretical basis from free algebras to free monoids. In addition, we show how lax monoidal functors enable the reuse of handlers and programs across different computation classes, for example, handling applicative computations with monadic handlers. We motivate and present these handler interfaces in the context of build systems. Tasks in a build system are represented by a free computation and their interpretation as a handler. This use case is based on the work of Mokhov et al. [(2018). PACMPL 2 (ICFP), 79:1–79:29.].