Bidirectionalization for free! (Pearl)

A bidirectional transformation consists of a function get that takes a source (document or value) to a view and a function put that takes an updated view and the original source back to an updated source, governed by certain consistency conditions relating the two functions. Both the database and programming language communities have studied techniques that essentially allow a user to specify only one of get and put and have the other inferred automatically. All approaches so far to this bidirectionalization task have been syntactic in nature, either proposing a domain-specific language with limited expressiveness but built-in (and composable) backward components, or restricting get to a simple syntactic form from which some algorithm can synthesize an appropriate definition for put. Here we present a semantic approach instead. The idea is to take a general-purpose language, Haskell, and write a higher-order function that takes (polymorphic) get-functions as arguments and returns appropriate put-functions. All this on the level of semantic values, without being willing, or even able, to inspect the definition of get, and thus liberated from syntactic restraints. Our solution is inspired by relational parametricity and uses free theorems for proving the consistency conditions. It works beautifully.

[1]  Philip Wadler,et al.  The essence of functional programming , 1992, POPL '92.

[2]  Christopher Strachey,et al.  Fundamental Concepts in Programming Languages , 2000, High. Order Symb. Comput..

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

[4]  Philip Wadler,et al.  The essence of functional programming (Invited talk) , 1997 .

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

[6]  Nils Anders Danielsson,et al.  Fast and loose reasoning is morally correct , 2006, POPL '06.

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

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

[9]  G. Hutton,et al.  Chapter 25 Reasoning About Effects : Seeing the Wood Through the Trees , 2008 .

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

[11]  Thorsten Altenkirch,et al.  Foundations of Software Science and Computation Structures: 6th International Conference, FOSSACS 2003 Held as Part of the Joint European Conferences on Theory and Practice of Software, ETAPS 2003 Warsaw, Poland, April 7–11, 2003 Proceedings , 2003, Lecture Notes in Computer Science.

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

[13]  Joyce L. Vedral,et al.  Functional Programming Languages and Computer Architecture , 1989, Lecture Notes in Computer Science.

[14]  Janis Voigtländer,et al.  Asymptotic Improvement of Computations over Free Monads , 2008, MPC.

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

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

[17]  A. Pettorossi,et al.  Derivation of programs which traverse their input data only once , 1989 .

[18]  Paul F. Dietz,et al.  Two algorithms for maintaining order in a list , 1987, STOC.

[19]  Patricia Johann,et al.  Free theorems in the presence of seq , 2004, POPL.

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

[21]  Benjamin C. Pierce,et al.  Relational lenses: a language for updatable views , 2006, PODS '06.