一句话:提出基于代数可扩展效应的指称语义框架,由程序与处理器诱导等式定律,并证明模处理器等价是同余。
带有多重且相互作用的效应(如变异、跳转、IO)的程序推理长期困难:单体 monad 不组合,效应交互可能使各自等式定律失效并产生涌现性质;判断定律是否充分、加入新效应后是否仍成立也不易。本文基于代数可扩展效应框架,采用指称语义,不把等式定律强加于程序或效应处理器,而是由程序和处理器诱导定律并澄清边条件。作者提出“模处理器”(或模观察/处理器组合)的等价概念,并证明其在特定条件下是同余,故可用于任意上下文而不仅是求值上下文。文中给出非确定性的现实处理器及其定律,并展示在全局状态存在时非确定性的等式定律。
Abstract The challenge of reasoning about programs with (multiple) effects such as mutation, jumps, or IO dates back to the inception of program semantics in the works of Strachey and Landin. Using monads to represent individual effects and the associated equational laws to reason about them proved exceptionally effective. Even then it is not always clear what laws are to be associated with a monad—for a good reason, as we show for non-determinism. Combining expressions using different effects brings challenges not just for monads, which do not compose, but also for equational reasoning: the interaction of effects may invalidate their individual laws, as well as induce emerging properties that are not apparent in the semantics of individual effects. Overall, the problems are judging the adequacy of a law; determining if or when a law continues to hold upon addition of new effects; and obtaining and easily verifying emergent laws. We present a solution relying on the framework of (algebraic, extensible) effects, which already proved itself for writing programs with multiple effects. Equipped with a fairly conventional denotational semantics, this framework turns useful, as we demonstrate, also for reasoning about and optimizing programs with multiple interacting effects. Unlike the conventional approach, equational laws are not imposed on programs/effect handlers, but induced from them: our starting point hence is a program (model), whose denotational semantics, besides being used directly, suggests and justifies equational laws and clarifies side conditions. The main technical result is the introduction of the notion of equivalence modulo handlers (“modulo observation”) or a particular combination of handlers—and proving it to be a congruence . It is hence usable for reasoning in any context, not just evaluation contexts—provided particular conditions are met. Concretely, we describe several realistic handlers for non-determinism and elucidate their laws (some of which hold in the presence of any other effect). We demonstrate appropriate equational laws of non-determinism in the presence of global state, which have been a challenge to state and prove before.
DOI 原文 ·
@article{paperbot1224,
title = {Not by equations alone: Reasoning with extensible effects},
author = {OLEG KISELYOV and SHIN-CHENG MU and AMR SABRY},
journal = {Journal of Functional Programming},
volume = {31},
year = {2021},
doi = {10.1017/s0956796820000271}
}