skip to main content
research-article

Applicative bidirectional programming with lenses

Published: 29 August 2015 Publication History

Abstract

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. One way to reduce the development and maintenance effort of bidirectional transformations is to have specialized languages in which the resulting programs are bidirectional by construction---giving rise to the paradigm of bidirectional programming. In this paper, we develop a framework for applicative-style and higher-order bidirectional programming, in which we can write bidirectional transformations as unidirectional programs in standard functional languages, opening up access to the bundle of language features previously only available to conventional unidirectional languages. Our framework essentially bridges two very different approaches of bidirectional programming, namely the lens framework and Voigtländer's semantic bidirectionalization, creating a new programming style that is able to bag benefits from both.

References

[1]
F. Bancilhon and N. Spyratos. Update semantics of relational views. ACM Trans. Database Syst., 6(4):557–575, 1981.
[2]
D. M. J. Barbosa, J. Cretin, N. Foster, M. Greenberg, and B. C. Pierce. Matching lenses: alignment and view update. In P. Hudak and S. Weirich, editors, ICFP, pages 193–204. ACM, 2010.
[3]
R. S. Bird, J. Gibbons, S. Mehner, J. Voigtländer, and T. Schrijvers. Understanding idiomatic traversals backwards and forwards. In C. chieh Shan, editor, Haskell, pages 25–36. ACM, 2013.
[4]
A. Bohannon, J. N. Foster, B. C. Pierce, A. Pilkiewicz, and A. Schmitt. Boomerang: resourceful lenses for string data. In G. C. Necula and P. Wadler, editors, POPL, pages 407–419. ACM, 2008.
[5]
A. Chlipala. Parametric higher-order abstract syntax for mechanized semantics. In J. Hook and P. Thiemann, editors, ICFP, pages 143–156. ACM, 2008.
[6]
U. Dayal and P. A. Bernstein. On the correct translation of update operations on relational views. ACM Trans. Database Syst., 7(3):381– 416, 1982.
[7]
T. Ellis. Category and lenses, Sep 2012.
[8]
Blog post: http://web.jaguarpaw.co.uk/~tom/blog/posts/ 2012-09-30-category-and-lenses.html.
[9]
L. Fegaras. Propagating updates through XML views using lineage tracing. In F. Li, M. M. Moro, S. Ghandeharizadeh, J. R. Haritsa, G. Weikum, M. J. Carey, F. Casati, E. Y. Chang, I. Manolescu, S. Mehrotra, U. Dayal, and V. J. Tsotras, editors, ICDE, pages 309–320. IEEE, 2010.
[10]
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 Trans. Program. Lang. Syst., 29(3), 2007.
[11]
J. N. Foster, A. Pilkiewicz, and B. C. Pierce. Quotient lenses. In J. Hook and P. Thiemann, editors, ICFP, pages 383–396. ACM, 2008.
[12]
N. Foster, K. Matsuda, and J. Voigtländer. Three complementary approaches to bidirectional programming. In J. Gibbons, editor, SSGIP, volume 7470 of Lecture Notes in Computer Science, pages 1–46. Springer, 2010.
[13]
Y. Hayashi, D. Liu, K. Emoto, K. Matsuda, Z. Hu, and M. Takeichi. A web service architecture for bidirectional XML updating. In G. Dong, X. Lin, W. Wang, Y. Yang, and J. X. Yu, editors, APWeb/WAIM, volume 4505 of Lecture Notes in Computer Science, pages 721–732. Springer, 2007.
[14]
S. J. Hegner. Foundations of canonical update support for closed database views. In S. Abiteboul and P. C. Kanellakis, editors, ICDT, volume 470 of Lecture Notes in Computer Science, pages 422–436. Springer, 1990.
[15]
S. Hidaka, Z. Hu, K. Inaba, H. Kato, K. Matsuda, and K. Nakano. Bidirectionalizing graph transformations. In P. Hudak and S. Weirich, editors, ICFP, pages 205–216. ACM, 2010.
[16]
M. Hofmann, B. C. Pierce, and D. Wagner. Symmetric lenses. In T. Ball and M. Sagiv, editors, POPL, pages 371–384. ACM, 2011.
[17]
Z. Hu, S.-C. Mu, and M. Takeichi. A programmable editor for developing structured documents based on bidirectional transformations. In N. Heintze and P. Sestoft, editors, PEPM, pages 178–189. ACM, 2004.
[18]
M. Jaskelioff and R. O’Connor. A representation theorem for secondorder functionals. CoRR, abs/1402.1699, 2014.
[19]
S. Lindley, P. Wadler, and J. Yallop. Idioms are oblivious, arrows are meticulous, monads are promiscuous. Electr. Notes Theor. Comput. Sci., 229(5):97–117, 2011.
[20]
S. Mac Lane. Categories for the Working Mathematician, volume 5 of Graduate Texts in Matheematics. Springer, second edition edition, 1998.
[21]
K. Matsuda, Z. Hu, K. Nakano, M. Hamana, and M. Takeichi. Bidirectionalization transformation based on automatic derivation of view complement functions. In R. Hinze and N. Ramsey, editors, ICFP, pages 47–58. ACM, 2007.
[22]
K. Matsuda and M. Wang. Bidirectionalization for free with runtime recording: or, a light-weight approach to the view-update problem. In R. Peña and T. Schrijvers, editors, PPDP, pages 297–308. ACM, 2013.
[23]
K. Matsuda and M. Wang. “Bidirectionalization for free” for monomorphic transformations. Science of Computer Programming, 2014.
[24]
C. McBride and R. Paterson. Applicative programming with effects. J. Funct. Program., 18(1):1–13, 2008.
[25]
B. Milewski. Lenses, Stores, and Yoneda, Oct 2013.
[26]
blog post: http://bartoszmilewski.com/2013/10/08/ lenses-stores-and-yoneda/.
[27]
S.-C. Mu, Z. Hu, and M. Takeichi. An algebraic approach to bidirectional updating. In W.-N. Chin, editor, APLAS, volume 3302 of Lecture Notes in Computer Science, pages 2–20. Springer, 2004.
[28]
R. O’Connor. Functor is to lens as applicative is to biplate: Introducing multiplate. CoRR, abs/1103.2841, 2011. Accepted in WGP’11, but not included in its proceedings.
[29]
H. Pacheco, Z. Hu, and S. Fischer. Monadic combinators for "putback" style bidirectional programming. In W.-N. Chin and J. Hage, editors, PEPM, pages 39–50. ACM, 2014.
[30]
R. Paterson. A new notation for arrows. In B. C. Pierce, editor, ICFP, pages 229–240. ACM, 2001.
[31]
R. Paterson. Constructing applicative functors. In J. Gibbons and P. Nogueira, editors, MPC, volume 7342 of Lecture Notes in Computer Science, pages 300–323. Springer, 2012.
[32]
R. Rajkumar, S. Lindley, N. Foster, and J. Cheney. Lenses for web data. In Preliminary Proceedings of Second International Workshop on Bidirectional Transformations (BX 2013), 2013.
[33]
J. C. Reynolds. Types, abstraction and parametric polymorphism. In R. Mason, editor, Information Processing, pages 513–523. Elsevier Science Publishers B.V. (North-Holland), 1983.
[34]
T. van Laarhoven. Cps based functional references, Jul 2009.
[35]
blog post: http://www.twanvl.nl/blog/haskell/ cps-functional-references.
[36]
J. Voigtländer. Bidirectionalization for free! (pearl). In Z. Shao and B. C. Pierce, editors, POPL, pages 165–176. ACM, 2009.
[37]
J. Voigtländer. Free theorems involving type constructor classes: functional pearl. In G. Hutton and A. P. Tolmach, editors, ICFP, pages 173–184. ACM, 2009.
[38]
J. Voigtländer, Z. Hu, K. Matsuda, and M. Wang. Combining syntactic and semantic bidirectionalization. In P. Hudak and S. Weirich, editors, ICFP, pages 181–192. ACM, 2010.
[39]
J. Voigtländer, Z. Hu, K. Matsuda, and M. Wang. Enhancing semantic bidirectionalization via shape bidirectionalizer plug-ins. J. Funct. Program., 23(5):515–551, 2013.
[40]
P. Wadler. Theorems for free! In FPCA, pages 347–359, 1989.
[41]
M. Wang, J. Gibbons, K. Matsuda, and Z. Hu. Gradual refinement: Blending pattern matching with data abstraction. In C. Bolduc, J. Desharnais, and B. Ktari, editors, MPC, volume 6120 of Lecture Notes in Computer Science, pages 397–425. Springer, 2010.
[42]
M. Wang, J. Gibbons, K. Matsuda, and Z. Hu. Refactoring pattern matching. Sci. Comput. Program., 78(11):2216–2242, 2013.
[43]
M. Wang, J. Gibbons, and N. Wu. Incremental updates for efficient bidirectional transformations. In M. M. T. Chakravarty, Z. Hu, and O. Danvy, editors, ICFP, pages 392–403. ACM, 2011.
[44]
M. Wang and S. Najd. Semantic bidirectionalization revisited. In W.-N. Chin and J. Hage, editors, PEPM, pages 51–62. ACM, 2014.
[45]
Y. Xiong, D. Liu, Z. Hu, H. Zhao, M. Takeichi, and H. Mei. Towards automatic model synchronization from model transformations. In R. E. K. Stirewalt, A. Egyed, and B. Fischer, editors, ASE, pages 164– 173. ACM, 2007.
[46]
Y. Yu, Y. Lin, Z. Hu, S. Hidaka, H. Kato, and L. Montrieux. Maintaining invariant traceability through bidirectional transformations. In M. Glinz, G. C. Murphy, and M. Pezzè, editors, ICSE, pages 540–550. IEEE, 2012.

Cited By

View all

Recommendations

Comments

Information & Contributors

Information

Published In

cover image ACM SIGPLAN Notices
ACM SIGPLAN Notices  Volume 50, Issue 9
ICFP '15
September 2015
436 pages
ISSN:0362-1340
EISSN:1558-1160
DOI:10.1145/2858949
  • Editor:
  • Andy Gill
Issue’s Table of Contents
  • cover image ACM Conferences
    ICFP 2015: Proceedings of the 20th ACM SIGPLAN International Conference on Functional Programming
    August 2015
    436 pages
    ISBN:9781450336697
    DOI:10.1145/2784731
Permission to make digital or hard copies of all or part of this work for personal or classroom use is granted without fee provided that copies are not made or distributed for profit or commercial advantage and that copies bear this notice and the full citation on the first page. Copyrights for components of this work owned by others than the author(s) must be honored. Abstracting with credit is permitted. To copy otherwise, or republish, to post on servers or to redistribute to lists, requires prior specific permission and/or a fee. Request permissions from [email protected].

Publisher

Association for Computing Machinery

New York, NY, United States

Publication History

Published: 29 August 2015
Published in SIGPLAN Volume 50, Issue 9

Check for updates

Author Tags

  1. Bidirectional Programming
  2. Bidirectionalization
  3. Free Theorem
  4. Functional Programming
  5. Haskell
  6. Lens

Qualifiers

  • Research-article

Funding Sources

Contributors

Other Metrics

Bibliometrics & Citations

Bibliometrics

Article Metrics

  • Downloads (Last 12 months)24
  • Downloads (Last 6 weeks)3
Reflects downloads up to 13 Dec 2024

Other Metrics

Citations

Cited By

View all
  • (2024) Sparcl : A language for partially invertible computation Journal of Functional Programming10.1017/S095679682300012634Online publication date: 26-Jan-2024
  • (2020)Maintaining consistency in networks of models: bidirectional transformations in the largeSoftware and Systems Modeling (SoSyM)10.1007/s10270-019-00736-x19:1(39-65)Online publication date: 1-Jan-2020
  • (2019)Composing Bidirectional Programs MonadicallyProgramming Languages and Systems10.1007/978-3-030-17184-1_6(147-175)Online publication date: 6-Apr-2019
  • (2017)An axiomatic basis for bidirectional programmingProceedings of the ACM on Programming Languages10.1145/31581292:POPL(1-29)Online publication date: 27-Dec-2017
  • (2024)Incrementalizing Polynomial FunctorsProceedings of the 26th ACM International Workshop on Formal Techniques for Java-like Programs10.1145/3678721.3686231(44-49)Online publication date: 20-Sep-2024
  • (2024)Partial Bidirectionalization of Model Transformation LanguagesProceedings of the ACM/IEEE 27th International Conference on Model Driven Engineering Languages and Systems10.1145/3640310.3674083(1-12)Online publication date: 22-Sep-2024
  • (2024)Reconciling Partial and Local InvertibilityProgramming Languages and Systems10.1007/978-3-031-57267-8_3(59-89)Online publication date: 6-Apr-2024
  • (2023)Embedding by UnembeddingProceedings of the ACM on Programming Languages10.1145/36078307:ICFP(1-47)Online publication date: 30-Aug-2023
  • (2023)Contract lenses: Reasoning about bidirectional programs via calculationJournal of Functional Programming10.1017/S095679682300005933Online publication date: 6-Nov-2023
  • (2022)Synbit: synthesizing bidirectional programs using unidirectional sketchesFormal Methods in System Design10.1007/s10703-023-00436-961:2-3(198-247)Online publication date: 1-Dec-2022
  • Show More Cited By

View Options

Login options

View options

PDF

View or Download as a PDF file.

PDF

eReader

View online with eReader.

eReader

Media

Figures

Other

Tables

Share

Share

Share this Publication link

Share on social media