Contract lenses: Reasoning about bidirectional programs via calculation

被引:1
|
作者
Zhang, Hanliang [1 ]
Tang, Wenhao [2 ]
Xie, Ruifeng [3 ]
Wang, Meng [1 ]
Hu, Zhenjiang [3 ]
机构
[1] Univ Bristol, Bristol BS8 1QU, England
[2] Univ Edinburgh, Edinburgh EH8 9AB, Scotland
[3] Peking Univ, Beijing, Peoples R China
关键词
Bidirectional transformation - Clear specifications - Combinator - Construction approaches - Correct-by-construction - Correctness by construction - Equational reasoning - Multiple representation - Optimisations - Program calculation;
D O I
10.1017/S0956796823000059
中图分类号
TP31 [计算机软件];
学科分类号
081202 ; 0835 ;
摘要
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.
引用
收藏
页数:41
相关论文
共 50 条