Contract lenses: Reasoning about bidirectional programs via calculation

Hanliang Zhang, Wenhao Tang, Ruifeng Xie, Meng Wang, Zhenjiang Hu

Research output: Contribution to journalArticle (Academic Journal)peer-review

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 fold, filter, map, and 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.

Original languageEnglish
Article numbere10
Number of pages41
JournalJournal of Functional Programming
Volume33
DOIs
Publication statusPublished - 6 Nov 2023

Research Groups and Themes

  • Programming Languages

Fingerprint

Dive into the research topics of 'Contract lenses: Reasoning about bidirectional programs via calculation'. Together they form a unique fingerprint.

Cite this