"Bidirectionalization for free" for monomorphic transformations

A bidirectional transformation 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. Over the years, a lot of effort has been made to offer better language support for programming such transformations. In particular, a technique known as bidirectionalization is able to analyze and transform unidirectional programs written in general purpose languages, and "bidirectionalize" them.Among others, an approach termed semantic bidirectionalization proposed by Voigtlander stands out in terms of user-friendliness. A unidirectional program can be written using arbitrary language constructs, as long as the function it represents is polymorphic and the language constructs respect parametricity. The free theorems that follow from the polymorphic type of the program allow a kind of forensic examination of the transformation, determining its effect without examining its implementation. This is convenient, as the programmer is not restricted to using a particular syntax; but it does require the transformation to be polymorphic.In this paper, we lift this polymorphism requirement to improve the applicability of semantic bidirectionalization. Concretely, we provide a type class PackM γ α µ , which intuitively reads "a concrete datatype γ is abstracted to a type α, and the 'observations' made by a transformation on values of type γ are recorded by a monad µ". With PackM, we turn monomorphic transformations into polymorphic ones that are ready to be bidirectionalized. We demonstrate our technique with case studies of typical applications of bidirectional transformation, namely text processing, XML query and graph transformation, which were commonly considered beyond semantic bidirectionalization because of their monomorphic nature.

[1]  15th International Symposium on Principles and Practice of Declarative Programming, PPDP '13, Madrid, Spain, September 16-18, 2013 , 2013, PPDP.

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

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

[4]  Umeshwar Dayal,et al.  On the correct translation of update operations on relational views , 1982, TODS.

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

[6]  Soichiro Hidaka,et al.  Structural recursion for querying ordered graphs , 2013, ICFP.

[7]  Georg Gottlob,et al.  Properties and update semantics of consistent views , 1988, TODS.

[9]  Philip Wadler,et al.  Theorems for free! , 1989, FPCA.

[10]  Dan Suciu,et al.  UnQL: a query language and algebra for semistructured data based on structural recursion , 2000, The VLDB Journal.

[11]  Soichiro Hidaka,et al.  Graph-transformation verification using monadic second-order logic , 2011, PPDP.

[12]  Conor McBride,et al.  Applicative programming with effects , 2008, J. Funct. Program..

[13]  Colin Runciman,et al.  Haskell and XML: generic combinators or type-based translation? , 1999, ICFP '99.

[14]  Thomas Johnsson Efficient Graph Algorithms Using Lazy Monolithic Arrays , 1998, J. Funct. Program..

[15]  John C. Reynolds,et al.  Types, Abstraction and Parametric Polymorphism , 1983, IFIP Congress.

[16]  Martin Erwig,et al.  Graph Algorithms = Iteration + Data Structures? The Structure of Graph Algorithms and a Corresponding Style of Programming , 1992, WG.

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

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

[19]  Jennifer Widom,et al.  The Lorel query language for semistructured data , 1997, International Journal on Digital Libraries.

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

[21]  John Launchbury,et al.  Structuring depth-first search algorithms in Haskell , 1995, POPL '95.

[22]  Benjamin C. Pierce,et al.  Quotient lenses , 2008, ICFP.

[23]  Michael Johnson,et al.  Lens put-put laws: monotonic and mixed , 2012, Electron. Commun. Eur. Assoc. Softw. Sci. Technol..

[24]  Meng Wang,et al.  Bidirectionalization for free with runtime recording: or, a light-weight approach to the view-update problem , 2013, PPDP.

[25]  Bruno C. d. S. Oliveira,et al.  Functional programming with structured graphs , 2012, ICFP.

[26]  Soichiro Hidaka,et al.  A parameterized graph transformation calculus for finite graphs with monadic branches , 2013, PPDP.

[27]  Arthur M. Keller,et al.  Comment on Bancilhon and Spyratos' “Update semantics and relational views” , 1987, TODS.

[28]  Janis Voigtländer Free theorems involving type constructor classes: functional pearl , 2009, ICFP.

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

[30]  Patrik Jansson,et al.  Proofs for free - Parametricity for dependent types , 2012, J. Funct. Program..

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

[32]  Ralf Lämmel,et al.  Bidirectional Transformations: A Cross-Discipline Perspective , 2009, ICMT@TOOLS.

[33]  Stephanie Weirich,et al.  Under Consideration for Publication in J. Functional Programming Parametricity, Type Equality and Higher-order Polymorphism , 2022 .

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

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

[36]  Shin-Cheng Mu,et al.  An Algebraic Approach to Bi-directional Updating , 2004, APLAS.

[37]  Tom Schrijvers,et al.  Understanding idiomatic traversals backwards and forwards , 2013, Haskell '13.

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

[39]  Martin Erwig,et al.  Inductive graphs and functional graph algorithms , 2001, J. Funct. Program..

[40]  Paul Hudak,et al.  Proceeding of the 15th ACM SIGPLAN international conference on Functional programming, ICFP 2010, Baltimore, Maryland, USA, September 27-29, 2010 , 2010, ICFP.

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

[42]  Kazutaka Matsuda,et al.  Gradual Refinement , 2010, MPC.

[43]  Meng Wang,et al.  Semantic bidirectionalization revisited , 2014, PEPM '14.

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

[45]  Alberto O. Mendelzon,et al.  GraphLog: a visual formalism for real life recursion , 1990, PODS '90.

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

[47]  Meng Wang,et al.  Incremental updates for efficient bidirectional transformations , 2011, ICFP '11.

[48]  Stephen J. Hegner,et al.  An Order-Based Theory of Updates for Closed Database Views , 2004, Annals of Mathematics and Artificial Intelligence.