×

Formalizing semantic bidirectionalization and extensions with dependent types. (English) Zbl 1353.68042

Summary: Bidirectional programming is concerned with pairs of transformations that together realize the forward and backward relationship between two data domains. Semantic bidirectionalization is a specific technique that takes a get-function (mapping forward from sources to views) as input and automatically gives a put-function (mapping an original source and an updated view back to an updated source), while guaranteeing standard well-behavedness properties. Proofs of those properties have been done by hand originally, and later extensions of the technique have also come with by-hand proofs or sketches thereof.
Here we provide a formalization of semantic bidirectionalization and proof of those properties in the dependently typed programming language Agda. We then explore two previously considered variations of the original technique, using our initial formalization as a baseline and showing that the well-behavedness properties are preserved as adjustments are made. Also, we find that using very precise types pays off, as a means to express insight about the bidirectionalization technique and by even allowing us to further improve it. In particular, shape-changing updates are known to be problematic for semantic bidirectionalization, and one of the variations considered addresses this by using “shape bidirectionalizers”. In the past, these have been thought of as extra components, but by leveraging information about the relationship between the shapes of sources and views now being expressed at the type level, we show that these “plug-ins” can sometimes be replaced by just type inference.
Beside the results about bidirectionalization, the article may also serve as an introduction and concrete example of using Agda to formalize and verify applications of functional programming.

MSC:

68N18 Functional programming and lambda calculus
68N15 Theory of programming languages

Software:

PoplMark; Agda
Full Text: DOI

References:

[1] Abbott, Michael; Altenkirch, Thorsten; Ghani, Neil, Categories of containers, (Foundations of Software Science and Computational Structures, Proceedings. Foundations of Software Science and Computational Structures, Proceedings, Lecture Notes in Computer Science, vol. 2620 (2003), Springer), 23-38 · Zbl 1029.68096
[2] Aydemir, Brian; Bohannon, Aaron; Fairbairn, Matthew; Foster, Nate; Pierce, Benjamin; Sewell, Peter; Vytiniotis, Dimitrios; Washburn, Geoffrey; Weirich, Stephanie; Zdancewic, Steve, Mechanized metatheory for the masses: the PoplMark challenge, (Theorem Proving in Higher Order Logics, Proceedings. Theorem Proving in Higher Order Logics, Proceedings, Lecture Notes in Computer Science, vol. 3603 (2005), Springer), 50-65 · Zbl 1152.68516
[3] Bancilhon, François; Spyratos, Nicolas, Update semantics of relational views, ACM Trans. Database Syst., 6, 4, 557-575 (1981) · Zbl 0465.68059
[4] Bernardy, Jean-Philippe; Moulin, Guilhem, Type-theory in color, (International Conference on Functional Programming, Proceedings (2013), ACM), 61-72 · Zbl 1323.68198
[5] Bernardy, Jean-Philippe; Jansson, Patrik; Paterson, Ross, Proofs for free: parametricity for dependent types, J. Funct. Program., 22, 2, 107-152 (2012) · Zbl 1271.68076
[6] Bohannon, Aaron; Pierce, Benjamin; Vaughan, Jeffrey, Relational lenses: a language for updatable views, (Principles of Database Systems, Proceedings (2006), ACM), 338-347
[7] Czarnecki, Krzysztof; Foster, Nate; Hu, Zhenjiang; Lämmel, Ralf; Schürr, Andy; Terwilliger, James, Bidirectional transformations: a cross-discipline perspective, (International Conference on Model Transformation, Proceedings. International Conference on Model Transformation, Proceedings, Lecture Notes in Computer Science, vol. 5563 (2009), Springer), 260-283
[8] Dagand, Pierre-Évariste; McBride, Conor, Transporting functions across ornaments, (International Conference on Functional Programming, Proceedings (2012), ACM), 103-114 · Zbl 1291.68139
[9] Dagand, Pierre-Évariste; McBride, Conor, A categorical treatment of ornaments, (Logic in Computer Science, Proceedings (2013), IEEE), 530-539 · Zbl 1366.68021
[10] Danielsson, Nils Anders, The Agda standard library version 0.9 (2014), last accessed: July 2015
[11] Foster, Nate; Greenwald, Michael; Moore, Jonathan; Pierce, Benjamin; Schmitt, Alan, Combinators for bidirectional tree transformations: a linguistic approach to the view-update problem, ACM Trans. Program. Lang. Syst., 29, 3, 17 (2007)
[12] Foster, Nate; Matsuda, Kazutaka; Voigtländer, Janis, Three complementary approaches to bidirectional programming, (Spring School on Generic and Indexed Programming (SSGIP 2010), Revised Lectures. Spring School on Generic and Indexed Programming (SSGIP 2010), Revised Lectures, Lecture Notes in Computer Science, vol. 7470 (2012), Springer), 1-46 · Zbl 1374.68103
[13] Grohne, Helmut, Formalizing semantic bidirectionalization in Agda (2013), University of Bonn, Agda formalization available at
[14] Grohne, Helmut; Löh, Andres; Voigtländer, Janis, Formalizing semantic bidirectionalization with dependent types, (Bidirectional Transformations (BX). Bidirectional Transformations (BX), CEUR Workshop Proceedings, vol. 1133 (2014)), 75-81
[15] Hidaka, Soichiro; Hu, Zhenjiang; Inaba, Kazuhiro; Kato, Hiroyuki; Matsuda, Kazutaka; Nakano, Keisuke, Bidirectionalizing graph transformations, (International Conference on Functional Programming, Proceedings (2010), ACM), 205-216 · Zbl 1323.68075
[16] Hu, Zhenjiang; Mu, Shin-Cheng; Takeichi, Masato, A programmable editor for developing structured documents based on bidirectional transformations, High.-Order Symb. Comput., 21, 1-2, 89-118 (2008) · Zbl 1194.68096
[17] Ko, Hsiang-Shang; Gibbons, Jeremy, Modularising inductive families, Prog. Inform., 10, 65-88 (2013)
[18] Matsuda, Kazutaka; Wang, Meng, “Bidirectionalization for free” for monomorphic transformations, Sci. Comput. Program., 111, 79-109 (2015)
[19] Matsuda, Kazutaka; Wang, Meng, Applicative bidirectional programming with lenses, (International Conference on Functional Programming, Proceedings (2015), ACM), 62-74 · Zbl 1360.68335
[20] Matsuda, Kazutaka; Hu, Zhenjiang; Nakano, Keisuke; Hamana, Makoto; Takeichi, Masato, Bidirectionalization transformation based on automatic derivation of view complement functions, (International Conference on Functional Programming, Proceedings (2007), ACM), 47-58 · Zbl 1291.68147
[21] Norell, Ulf, Dependently typed programming in Agda, (Advanced Functional Programming. Advanced Functional Programming, AFP 2008, Revised Lectures. Advanced Functional Programming. Advanced Functional Programming, AFP 2008, Revised Lectures, Lecture Notes in Computer Science, vol. 5832 (2009), Springer), 230-266 · Zbl 1263.68038
[22] Voigtländer, Janis, Bidirectionalization for free!, (Principles of Programming Languages, Proceedings (2009), ACM), 165-176 · Zbl 1315.68059
[23] Voigtländer, Janis; Hu, Zhenjiang; Matsuda, Kazutaka; Wang, Meng, Enhancing semantic bidirectionalization via shape bidirectionalizer plug-ins, J. Funct. Program., 23, 5, 515-551 (2013) · Zbl 1303.68039
[24] Wadler, Philip, Theorems for free!, (Functional Programming Languages and Computer Architecture, Proceedings (1989), ACM), 347-359
[25] Wang, Meng; Najd, Shayan, Semantic bidirectionalization revisited, (Partial Evaluation and Program Manipulation, Proceedings (2014), ACM), 51-61
This reference list is based on information provided by the publisher or from digital mathematics libraries. Its items are heuristically matched to zbMATH identifiers and may contain data conversion errors. In some cases that data have been complemented/enhanced by data from zbMATH Open. This attempts to reflect the references listed in the original paper as accurately as possible without claiming completeness or a perfect matching.