arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 2302.01415cs.PLcs.LO
收藏

高阶效果和处理程序的框架

A Framework for Higher-Order Effects & Handlers

Birthe van den Berg, Tom Schrijvers

摘要:

代数效果和处理程序是一种在函数式编程中建模副作用的模块化方法。它们的语法是根据有效操作的签名定义的,编码为一个函子,插入到自由monad中;它们的指称语义是由折叠样式的处理程序定义的,只解释它们的语法部分,并转发其余部分。然而,并非所有效应都是代数的:有些效应需要访问内部计算。例如,作用域效应区分作用域中的计算和作用域外的计算;并行效应在计算上并行,潜在效应推迟计算。已经为这些高阶效应及其相应的处理程序提出了单独的定义,通常会导致权宜和复杂的monad定义。在这项工作中,我们提出了一个通用的框架,高阶效果,推广代数效果和处理程序:一个通用的自由单子与高阶效果签名和相应的解释器。专门化这种高阶语法会导致对先前定义的(作用域、平行、潜在)和新颖(写入器、括号)效果的各种定义。此外,我们正式表明我们的框架理论上是正确的,也把不同的效果实例正式的基础上,一个显着的贡献平行,潜在的,作家和括号效果。

英文摘要:

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.

机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。

↑