skip to main content
research-article

Bidirectionalization for free! (Pearl)

Published:21 January 2009Publication History
Skip Abstract Section

Abstract

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.

References

  1. M. Abbott, T. Altenkirch, and N. Ghani. Categories of containers. In Foundations of Software Science and Computational Structures, Proceedings, volume 2620 of LNCS, pages 23--38. Springer-Verlag, 2003. Google ScholarGoogle ScholarDigital LibraryDigital Library
  2. F. Bancilhon and N. Spyratos. Update semantics of relational views. ACM Transactions on Database Systems, 6(3):557--575, 1981. Google ScholarGoogle ScholarDigital LibraryDigital Library
  3. A. Bohannon, B.C. Pierce, and J.A. Vaughan. Relational lenses: A language for updatable views. In Principles of Database Systems, Proceedings, pages 338--347. ACM Press, 2006. Google ScholarGoogle ScholarDigital LibraryDigital Library
  4. A. Bohannon, J.N. Foster, B.C. Pierce, A. Pilkiewicz, and A. Schmitt. Boomerang: Resourceful lenses for string data. In Principles of Programming Languages, Proceedings, pages 407--419. ACM Press, 2008. Google ScholarGoogle ScholarDigital LibraryDigital Library
  5. N.A. Danielsson, R.J.M. Hughes, P. Jansson, and J. Gibbons. Fast and loose reasoning is morally correct. In Principles of Programming Languages, Proceedings, pages 206--217. ACM Press, 2006. Google ScholarGoogle ScholarDigital LibraryDigital Library
  6. P.F. Dietz and D.D. Sleator. Two algorithms for maintaining order in a list. In Symposium on Theory of Computing, Proceedings, pages 365--372. ACM Press, 1987. Google ScholarGoogle ScholarDigital LibraryDigital Library
  7. J.N. Foster, M.B. Greenwald, J.T. Moore, B.C. Pierce, and A. Schmitt. Combinators for bidirectional tree transformations: A linguistic approach to the view--update problem. ACM Transactions on Programming Languages and Systems, 29(3):17, 2007. Google ScholarGoogle ScholarDigital LibraryDigital Library
  8. J.N. Foster, A. Pilkiewicz, and B.C. Pierce. Quotient lenses. In International Conference on Functional Programming, Proceedings, pages 383--395. ACM Press, 2008. Google ScholarGoogle ScholarDigital LibraryDigital Library
  9. Z. Hu, S.-C. Mu, and M. Takeichi. A programmable editor for developing structured documents based on bidirectional transformations. In Partial Evaluation and Semantics--Based Program Manipulation, Proceedings, pages 178--189. ACM Press, 2004. Google ScholarGoogle ScholarDigital LibraryDigital Library
  10. G. Hutton and D. Fulger. Reasoning about effects: Seeing the wood through the trees. In Trends in Functional Programming, Draft Proceedings, 2008.Google ScholarGoogle Scholar
  11. P. Johann and J. Voigtländer. Free theorems in the presence of seq. In Principles of Programming Languages, Proceedings, pages 99--110. ACM Press, 2004. Google ScholarGoogle ScholarDigital LibraryDigital Library
  12. K. Matsuda, Z. Hu, K. Nakano, M. Hamana, and M. Takeichi. Bidirectionalization transformation based on automatic derivation of view complement functions. In International Conference on Functional Programming, Proceedings, pages 47--58. ACM Press, 2007. Google ScholarGoogle ScholarDigital LibraryDigital Library
  13. C. McBride and R. Paterson. Applicative programming with effects. Journal of Functional Programming, 18(1):1--13, 2008. Google ScholarGoogle ScholarDigital LibraryDigital Library
  14. A. Pettorossi. Derivation of programs which traverse their input data only once. In Advanced School on Programming Methodologies, Proceedings, pages 165--184. Academic Press, 1987. Google ScholarGoogle ScholarDigital LibraryDigital Library
  15. J.C. Reynolds. Types, abstraction and parametric polymorphism. In Information Processing, Proceedings, pages 513--523. Elsevier, 1983.Google ScholarGoogle Scholar
  16. C. Strachey. Fundamental concepts in programming languages. In International Summer School in Computer Programming, Lecture Notes, 1967. Reprint appeared in Higher--Order and Symbolic Computation, 13(1--2):11--49, 2000. Google ScholarGoogle ScholarDigital LibraryDigital Library
  17. J. Voigtländer. Asymptotic improvement of computations over free monads. In Mathematics of Program Construction, Proceedings, volume 5133 of LNCS, pages 388--403. Springer--Verlag, 2008. Google ScholarGoogle ScholarDigital LibraryDigital Library
  18. P. Wadler. Theorems for free! In Functional Programming Languages and Computer Architecture, Proceedings, pages 347--359. ACM Press, 1989. Google ScholarGoogle ScholarDigital LibraryDigital Library
  19. P. Wadler. The essence of functional programming (Invited talk). In Principles of Programming Languages, Proceedings, pages 1--14. ACM Press, 1992. Google ScholarGoogle ScholarDigital LibraryDigital Library

Index Terms

  1. Bidirectionalization for free! (Pearl)

                  Recommendations

                  Comments

                  Login options

                  Check if you have access through your login credentials or your institution to get full access on this article.

                  Sign in

                  Full Access

                  PDF Format

                  View or Download as a PDF file.

                  PDF

                  eReader

                  View online with eReader.

                  eReader
                  About Cookies On This Site

                  We use cookies to ensure that we give you the best experience on our website.

                  Learn more

                  Got it!