一句话:提出隧道语义,使高阶效应多态代码不会意外处理传入函数引发的效应,从而保证效应处理器既类型安全又抽象安全。
代数效应处理器可统一异常、迭代与 async/await 等控制流,但以往的类型安全设计不支持高阶抽象的模块化推理:高阶效应多态代码可能意外处理传入函数引发的效应。本文提出“隧道”语义,核心是代码只处理自己感知的效应;传入函数引发的效应会穿过对其多态的高阶调用者,而不会被意外捕获,同时类型系统仍保证所有效应最终被处理。作者证明该设计不仅类型安全而且抽象安全,并建立相对于上下文等价可靠的逻辑关系模型,导出此前无法得到的程序等价结果,为兼具强抽象保证的效应处理器语言设计提供了可行方案。
Algebraic effect handlers offer a unified approach to expressing control-flow transfer idioms such as exceptions, iteration, and async/await. Unfortunately, previous attempts to make these handlers type-safe have failed to support the fundamental principle of modular reasoning for higher-order abstractions. We demonstrate that abstraction-safe algebraic effect handlers are possible by giving them a new semantics. The key insight is that code should only handle effects it is aware of. In our approach, the type system guarantees all effects are handled, but it is impossible for higher-order, effect-polymorphic code to accidentally handle effects raised by functions passed in; such effects tunnel through the higher-order, calling procedures polymorphic to them. By contrast, the possibility of accidental handling threatens previous designs for algebraic effect handlers. We prove that our design is not only type-safe, but also abstraction-safe. Using a logical-relations model that we prove sound with respect to contextual equivalence, we derive previously unattainable program equivalence results. Our mechanism offers a viable approach for future language designs aiming for effect handlers with strong abstraction guarantees.