HOBiT: Programming Lenses Without Using Lens Combinators

We propose HOBiT, a higher-order bidirectional programming language, in which users can write bidirectional programs in the familiar style of conventional functional programming, while enjoying the full expressiveness of lenses. A bidirectional transformation, or a lens, is a pair of mappings between source and view data objects, one in each direction. When the view is modified, the source is updated accordingly with respect to some laws—a pattern that is found in databases, model-driven development, compiler construction, and so on. The most common way of programming lenses is with lens combinators, which are lens-to-lens functions that compose simpler lenses to form more complex ones. Lens combinators preserve the bidirectionality of lenses and are expressive; but they compel programmers to a specialised point-free style—i.e., no naming of intermediate computation results—limiting the scalability of bidirectional programming. To address this issue, we propose a new bidirectional programming language HOBiT, in which lenses are represented as standard functions, and combinators are mapped to language constructs with binders. This design transforms bidirectional programming, enabling programmers to write bidirectional programs in a flexible functional style and at the same time access the full expressiveness of lenses. We formally define the syntax, type system, and the semantics of the language, and then show that programs in HOBiT satisfy bidirectionality. Additionally, we demonstrate HOBiT ’s programmability with examples.

[1]  Meng Wang,et al.  Enhancing semantic bidirectionalization via shape bidirectionalizer plug-ins , 2013, J. Funct. Program..

[2]  Meng Wang,et al.  Applicative bidirectional programming: Mixing lenses and semantic bidirectionalization , 2018, J. Funct. Program..

[3]  Robert Glück,et al.  Principles of a reversible programming language , 2008, CF '08.

[4]  Kazutaka Matsuda,et al.  Three Complementary Approaches to Bidirectional Programming , 2010, SSGIP.

[5]  Shin-Cheng Mu,et al.  A Grammar-Based Approach to Invertible Programs , 2010, ESOP.

[6]  Aarne Ranta,et al.  A pattern for almost compositional functions , 2008, J. Funct. Program..

[7]  Jerzy Tiuryn,et al.  A New Characterization of Lambda Definability , 1993, TLCA.

[8]  Zhenjiang Hu,et al.  Principles and Practice of Bidirectional Programming in BiGUL , 2016, Bidirectional Transformations.

[9]  Janis Voigtländer Bidirectionalization for free! (Pearl) , 2009, POPL '09.

[10]  Dongxi Liu,et al.  Towards automatic model synchronization from model transformations , 2007, ASE.

[11]  Benjamin C. Pierce,et al.  Combinators for bi-directional tree transformations: a linguistic approach to the view update problem , 2005, POPL '05.

[12]  Robert Glück,et al.  Revisiting an automatic program inverter for Lisp , 2005, SIGP.

[13]  Kazutaka Matsuda,et al.  Bidirectionalization transformation based on automatic derivation of view complement functions , 2007, ICFP '07.

[14]  Meng Wang,et al.  Refactoring pattern matching , 2013, Sci. Comput. Program..

[15]  James Cheney,et al.  Lenses for Web Data , 2013, Electron. Commun. Eur. Assoc. Softw. Sci. Technol..

[16]  Meng Wang,et al.  "Bidirectionalization for free" for monomorphic transformations , 2015, Sci. Comput. Program..

[17]  Martin Hofmann,et al.  Symmetric lenses , 2011, POPL '11.

[18]  Benjamin C. Pierce,et al.  Boomerang: resourceful lenses for string data , 2008, POPL '08.

[19]  J. Garrett Morris The best of both worlds: linear functional programming without compromise , 2016, ICFP.

[20]  Meng Wang,et al.  Combining syntactic and semantic bidirectionalization , 2010, ICFP '10.

[21]  Stephen J. Hegner,et al.  Foundations of Canonical Update Support for Closed Database Views , 1990, ICDT.

[22]  Martin Hofmann,et al.  Edit lenses , 2012, POPL '12.

[23]  Benjamin C. Pierce,et al.  Matching lenses: alignment and view update , 2010, ICFP '10.

[24]  Meng Wang,et al.  Applicative bidirectional programming with lenses , 2015, ICFP.

[25]  Leonidas Fegaras,et al.  Propagating updates through XML views using lineage tracing , 2010, 2010 IEEE 26th International Conference on Data Engineering (ICDE 2010).

[26]  Kazutaka Matsuda,et al.  Bidirectionalizing graph transformations , 2010, ICFP '10.

[27]  Shin-Cheng Mu,et al.  A programmable editor for developing structured documents based on bidirectional transformations , 2004, PEPM '04.

[28]  Nicolas Spyratos,et al.  Update semantics of relational views , 1981, TODS.

[29]  Robert Glück,et al.  A Program Inverter for a Functional Language with Equality and Constructors , 2003, APLAS.

[30]  Eugenio Moggi,et al.  Functor Categories and Two-Level Languages , 1998, FoSSaCS.

[31]  Shriram Krishnamurthi,et al.  Resugaring: lifting evaluation sequences through syntactic sugar , 2014, PLDI.

[32]  Perdita Stevens,et al.  A Landscape of Bidirectional Model Transformations , 2007, GTTSE.

[33]  Yijun Yu,et al.  Maintaining invariant traceability through bidirectional transformations , 2012, 2012 34th International Conference on Software Engineering (ICSE).