Algebraic effects & handlers are a modular approach for modeling side-effects in functional programming. Their syntax is defined in terms of a signature of effectful operations, encoded as a functor, that are plugged into the free monad; their denotational semantics is defined by fold-style handlers that only interpret their part of the syntax and forward the rest. However, not all effects are algebraic: some need to access an internal computation. For example, scoped effects distinguish between a computation in scope and out of scope; parallel effects parallellize over a computation, latent effects defer a computation. Separate definitions have been proposed for these higher-order effects and their corresponding handlers, often leading to expedient and complex monad definitions. In this work we propose a generic framework for higher-order effects, generalizing algebraic effects & handlers: a generic free monad with higher-order effect signatures and a corresponding interpreter. Specializing this higher-order syntax leads to various definitions of previously defined (scoped, parallel, latent) and novel (writer, bracketing) effects. Furthermore, we formally show our framework theoretically correct, also putting different effect instances on formal footing; a significant contribution for parallel, latent, writer and bracketing effects.
翻译:代数效应和处理器是一种模块化的方法,用于模拟功能编程中的副作用。它们的语法是按效果操作的标志来定义的。它们的语法是按效果操作的标志来定义的,编码成一个配料,插在自由的月球中;它们的分义语义由折式处理器来定义,这些处理器只解释其语法部分的语法和将其余部分向前。但是,并非所有效果都是代数:有些效果需要进入内部计算。例如,范围性和范围外的计算;在计算时的平行效应;平行效应,潜伏效应推迟计算。已经为这些较高级效应及其相应的处理器提出了不同的定义,常常导致快速和复杂的单调调定义。在这项工作中,我们提出了一个关于更高排序效果的通用框架,将变数效应和处理器:一个通用的自由调高调特征和相应的解释器。这种更高级的合成导致对先前定义的不同定义(范围、平行、平行、潜在)和新颖(书写、括号)和新书写效果作出不同的定义。此外,我们正式地展示了一种重大的平行作用。