Software frequently converts data from one representation to another and vice versa. Naively specifying both conversion directions separately is error prone and introduces conceptual duplication. Instead, bidirectional programming techniques allow programs to be written which can be interpreted in both directions. However, these techniques often employ unfamiliar programming idioms via restricted, specialised combinator libraries. Instead, we introduce a framework for composing bidirectional programs monadically, enabling bidirectional programming with familiar abstractions in functional languages such as Haskell. We demonstrate the generality of our approach applied to parsers/printers, lenses, and generators/predicates. We show how to leverage compositionality and equational reasoning for the verification of round-tripping properties for such monadic bidirectional programs.
翻译:软件经常将数据从一个表示式转换为另一个表示式,反之亦然。 单向指定两个转换方向容易出错,并引入概念上的重复。 相反, 双向编程技术允许两种方向都能对程序进行书面解释。 但是, 这些技术往往通过限制的、专门的组合式图书馆使用不熟悉的编程风格。 相反, 我们引入了一个双向编程框架, 以双向制成双向程序, 使双向编程能够以哈斯凯尔等功能性语言进行熟悉的抽象化。 我们展示了我们适用于剖析器/打印器、镜片和发电机/预设器的方法的通用性。 我们展示了如何利用组合性和方程推理来验证这些双向双向程序。