paperbot · PL 论文追踪

全部论文 待读 收藏

P2 Contract lenses: Reasoning about bidirectional programs via calculation

契约透镜:通过计算推理双向程序
JFP vol.332023匹配度 2/10 · 论文研究双向变换中的 contract lens 与程序演算,属于函数式编程与语言设计/形式化推导,与用户核心关注的 LLM/Agent 结合静态分析、浮点程序分析、贝叶斯程序分析均无直接关系;仅在“形式化方法”层面与 PL 方向有微弱邻近性。引用 4 inbox
HANLIANG ZHANG, WENHAO TANG, RUIFENG XIE, MENG WANG, ZHENJIANG HU
crossref: 2026-09-10

AI 速览

一句话:提出带谓词契约的 contract lens 与双向计算律,用程序演算从规约推导高效双向变换。

双向变换(BX)用于维护相关数据多个表示之间的一致性。基于 lens 组合子的方法因模块化和构造正确而成为 BX 编程主流,但 lens 的双向行为使等式推理与优化比单向程序困难得多。本文将程序演算——一种基于代数律对函数式程序进行构造正确推理的方法——引入双向程序推导。为支持双向程序计算,作者提出 contract lens,在传统 lens 上增加一对谓词,从而支持部分 lens 的安全、模块化组合;并定义 fold、filter、map、scan 等常见计算模式的组合子,建立若干双向计算律用于推理和优化 contract lens。最后通过非平凡例子展示该计算框架的有效性。

问题
双向变换的 lens 组合子方法虽模块化且构造正确,但其双向行为使等式推理与程序优化远比单向程序困难。
方法
提出 contract lens,用一对谓词扩展传统 lens 以支持部分 lens 的安全模块化组合,并定义 fold、filter、map、scan 等组合子及双向计算律,通过程序演算从清晰规约推导高效 lens。
评估
通过若干非平凡实例展示基于 contract lens 的双向计算框架在双向程序推理与优化中的有效性。
原文摘要(Abstract)

Abstract Bidirectional transformations (BXs) are a mechanism for maintaining consistency between multiple representations of related data. The lens framework, which usually constructs BXs from lens combinators, has become the mainstream approach to BX programming because of its modularity and correctness by construction. However, the involved bidirectional behaviors of lenses make the equational reasoning and optimization of them much harder than unidirectional programs. We propose a novel approach to deriving efficient lenses from clear specifications via program calculation, a correct-by-construction approach to reasoning about functional programs by algebraic laws. To support bidirectional program calculation, we propose contract lenses , which extend conventional lenses with a pair of predicates to enable safe and modular composition of partial lenses. We define several contract-lens combinators capturing common computation patterns including $\textit{fold}, \textit{filter},\textit{map}$ , and $\textit{scan}$ , and develop several bidirectional calculation laws to reason about and optimize contract lenses. We demonstrate the effectiveness of our new calculation framework based on contract lenses with nontrivial examples.

链接与引用

DOI 原文 · PDF(开放获取) ·

BibTeX
@article{paperbot2154,
  title = {Contract lenses: Reasoning about bidirectional programs via calculation},
  author = {HANLIANG ZHANG and WENHAO TANG and RUIFENG XIE and MENG WANG and ZHENJIANG HU},
  journal = {Journal of Functional Programming},
  volume = {33},
  year = {2023},
  doi = {10.1017/s0956796823000059}
}