Contract lenses: Reasoning about bidirectional programs via calculation

IF 1.1 3区 计算机科学 Q4 COMPUTER SCIENCE, SOFTWARE ENGINEERING Journal of Functional Programming Pub Date : 2023-01-01 DOI:10.1017/s0956796823000059
HANLIANG ZHANG, WENHAO TANG, RUIFENG XIE, MENG WANG, ZHENJIANG HU
{"title":"Contract lenses: Reasoning about bidirectional programs via calculation","authors":"HANLIANG ZHANG, WENHAO TANG, RUIFENG XIE, MENG WANG, ZHENJIANG HU","doi":"10.1017/s0956796823000059","DOIUrl":null,"url":null,"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.","PeriodicalId":15874,"journal":{"name":"Journal of Functional Programming","volume":"46 1","pages":"0"},"PeriodicalIF":1.1000,"publicationDate":"2023-01-01","publicationTypes":"Journal Article","fieldsOfStudy":null,"isOpenAccess":false,"openAccessPdf":"","citationCount":"0","resultStr":null,"platform":"Semanticscholar","paperid":null,"PeriodicalName":"Journal of Functional Programming","FirstCategoryId":"1085","ListUrlMain":"https://doi.org/10.1017/s0956796823000059","RegionNum":3,"RegionCategory":"计算机科学","ArticlePicture":[],"TitleCN":null,"AbstractTextCN":null,"PMCID":null,"EPubDate":"","PubModel":"","JCR":"Q4","JCRName":"COMPUTER SCIENCE, SOFTWARE ENGINEERING","Score":null,"Total":0}
引用次数: 0

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.
查看原文
分享 分享
微信好友 朋友圈 QQ好友 复制链接
本刊更多论文
契约透镜:通过计算对双向程序进行推理
双向转换(BXs)是一种保持相关数据的多个表示之间一致性的机制。透镜框架通常由透镜组合子构造BX,由于其模块化和构造正确性,已经成为BX编程的主流方法。然而,透镜的双向行为使得它们的方程推理和优化比单向编程要困难得多。我们提出了一种新的方法,通过程序计算从清晰的规范中推导出有效的透镜,这是一种通过代数定律来推理函数程序的正确构造方法。为了支持双向程序计算,我们提出了契约透镜,它用一对谓词扩展了传统透镜,以实现部分透镜的安全和模块化组成。我们定义了几个契约透镜组合子,捕获了常见的计算模式,包括$\textit{fold}, \textit{filter},\textit{map}$和$\textit{scan}$,并开发了几个双向计算定律来推理和优化契约透镜。我们用非平凡的例子证明了基于收缩透镜的新计算框架的有效性。
本文章由计算机程序翻译,如有差异,请以英文原文为准。
求助全文
约1分钟内获得全文 去求助
来源期刊
Journal of Functional Programming
Journal of Functional Programming 工程技术-计算机:软件工程
CiteScore
1.70
自引率
0.00%
发文量
9
审稿时长
>12 weeks
期刊介绍: Journal of Functional Programming is the only journal devoted solely to the design, implementation, and application of functional programming languages, spanning the range from mathematical theory to industrial practice. Topics covered include functional languages and extensions, implementation techniques, reasoning and proof, program transformation and synthesis, type systems, type theory, language-based security, memory management, parallelism and applications. The journal is of interest to computer scientists, software engineers, programming language researchers and mathematicians interested in the logical foundations of programming.
期刊最新文献
Signature restriction for polymorphic algebraic effects Asymptotic speedup via effect handlers Static Blame for gradual typing Knuth–Morris–Pratt illustrated Sparcl: A language for partially invertible computation
×
引用
GB/T 7714-2015
复制
MLA
复制
APA
复制
导出至
BibTeX EndNote RefMan NoteFirst NoteExpress
×
×
提示
您的信息不完整,为了账户安全,请先补充。
现在去补充
×
提示
您因"违规操作"
具体请查看互助需知
我知道了
×
提示
现在去查看 取消
×
提示
确定
0
微信
客服QQ
Book学术公众号 扫码关注我们
反馈
×
意见反馈
请填写您的意见或建议
请填写您的手机或邮箱
已复制链接
已复制链接
快去分享给好友吧!
我知道了
×
扫码分享
扫码分享
Book学术官方微信
Book学术文献互助
Book学术文献互助群
群 号:481959085
Book学术
文献互助 智能选刊 最新文献 互助须知 联系我们:info@booksci.cn
Book学术提供免费学术资源搜索服务,方便国内外学者检索中英文文献。致力于提供最便捷和优质的服务体验。
Copyright © 2023 Book学术 All rights reserved.
ghs 京公网安备 11010802042870号 京ICP备2023020795号-1