从高阶到低阶:用状态模拟非确定性与状态
From High to Low: Simulating Nondeterminism and State with State
AI总结:
本文研究代数效应与处理器机制,通过三步翻译将Prolog式局部状态这种高阶非确定性状态效应映射为类似沃伦抽象机的低阶复合状态效应,并基于效应处理器融合律用程序演算证明各步骤正确性,实现高阶抽象与低阶优化的兼顾。
摘要:
某些效应被认为比其他效应层级更高。高阶效应为编程概念提供了表达力强且简洁的抽象,而低阶效应允许对程序执行和资源进行更细粒度的控制。然而,人们通常希望既能利用高阶效应提供的便捷抽象编写程序,同时又能受益于低阶效应带来的优化。一种解决方案是将高阶效应翻译为低阶效应。\n本文研究了代数效应与处理器(algebraic effects and handlers)如何让我们能够用低阶效应模拟高阶效应。具体而言,我们聚焦于状态与非确定性之间的相互作用,即Prolog所提供的局部状态(local state)。我们将这种高阶语义逐步映射到一种低阶复合状态效应上,该效应类似于Prolog的Warren Abstract Machine(沃伦抽象机)所管理的状态效应。我们首先通过在回溯时显式恢复状态更新,给出了从高阶局部状态语义到低阶全局状态语义的翻译。接着,我们彻底消除了非确定性,转而采用包含选择点栈(choicepoint stack)的更低层级状态。随后,我们通过仅使用增量式、可逆的状态更新来避免复制状态。我们展示了如何通过另一种状态效应将这些更新存储在追踪栈(trail stack)上。我们使用程序演算(program calculation)证明了所有步骤的正确性,其中效应处理器的融合律(fusion laws of effect handlers)发挥了核心作用。
英文摘要:
Some effects are considered to be higher-level than others. High-level effects provide expressive and succinct abstraction of programming concepts, while low-level effects allow more fine-grained control over program execution and resources. Yet, often it is desirable to write programs using the convenient abstraction offered by high-level effects, and meanwhile still benefit from the optimisations enabled by low-level effects. One solution is to translate high-level effects to low-level ones. This paper studies how algebraic effects and handlers allow us to simulate high-level effects in terms of low-level effects. In particular, we focus on the interaction between state and nondeterminism known as the local state, as provided by Prolog. We map this high-level semantics in successive steps onto a low-level composite state effect, similar to that managed by Prolog's Warren Abstract Machine. We first give a translation from the high-level local-state semantics to the low-level global-state semantics, by explicitly restoring state updates on backtracking. Next, we eliminate nondeterminsm altogether in favor of a lower-level state containing a choicepoint stack. Then we avoid copying the state by restricting ourselves to incremental, reversible state updates. We show how these updates can be stored on a trail stack with another state effect. We prove the correctness of all our steps using program calculation where the fusion laws of effect handlers play a central role.
机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。