Bidirectional Programming Languages
Total Page:16
File Type:pdf, Size:1020Kb
University of Pennsylvania ScholarlyCommons Publicly Accessible Penn Dissertations Winter 2009 Bidirectional Programming Languages John Nathan Foster University of Pennsylvania, [email protected] Follow this and additional works at: https://repository.upenn.edu/edissertations Part of the Databases and Information Systems Commons, and the Programming Languages and Compilers Commons Recommended Citation Foster, John Nathan, "Bidirectional Programming Languages" (2009). Publicly Accessible Penn Dissertations. 56. https://repository.upenn.edu/edissertations/56 This paper is posted at ScholarlyCommons. https://repository.upenn.edu/edissertations/56 For more information, please contact [email protected]. Bidirectional Programming Languages Abstract The need to edit source data through a view arises in a host of applications across many different areas of computing. Unfortunately, few existing systems provide support for updatable views. In practice, when they are needed, updatable views are usually implemented using two separate programs: one that computes the view from the source and another that handles updates. This rudimentary design is tedious for programmers, difficult to reason about, and a nightmare to maintain. This dissertation presents bidirectional programming languages, which provide an elegant and effective mechanism for describing updatable views. Unlike programs written in an ordinary language, which only work in one direction, programs in a bidirectional language can be run both forwards and backwards: from left to right, they describe functions that map sources to views, and from right to left, they describe functions that map updated views back to updated sources. Besides eliminating redundancy, these languages can be designed to ensure correctness, guaranteeing by construction that the two functions work well together. Starting from the foundations, we define a general semantic space of well-behaved bidirectional transformations called lenses. Then, building on this foundation, we describe a particular language for defining lenses on strings with syntax based on the familiar egularr operators (union, concatenation, and Kleene star). We present extensions to the basic framework that address the subtle complications that arise when lenses are used to manipulate, data containing unimportant details, ordered data, and confidential data. Degree Type Dissertation Degree Name Doctor of Philosophy (PhD) Graduate Group Computer and Information Science First Advisor Benjamin C. Pierce Keywords bidirectional languages, lenses, view update, regular expression types Subject Categories Databases and Information Systems | Programming Languages and Compilers This dissertation is available at ScholarlyCommons: https://repository.upenn.edu/edissertations/56 BIDIRECTIONAL PROGRAMMING LANGUAGES John Nathan Foster A DISSERTATION in Computer and Information Science Presented to the Faculties of the University of Pennsylvania in Partial Fulllment of the Requirements for the Degree of Doctor of Philosophy 2009 Benjamin C. Pierce, Professor of Computer and Information Science Supervisor of Dissertation Jianbo Shi, Associate Professor of Computer and Information Science Graduate Group Chairperson Dissertation Committee Zachary G. Ives, Associate Professsor of Computer and Information Science Val Tannen, Professor of Computer and Information Science Philip Wadler, Professor of Theoretical Computer Science, University of Edinburgh Steve Zdancewic, Associate Professor of Computer and Information Science COPYRIGHT John Nathan Foster 2009 ABSTRACT Bidirectional Programming Languages John Nathan Foster Supervisor: Benjamin C. Pierce The need to edit source data through a view arises in a host of applications across many different areas of computing. Unfortunately, few existing systems provide support for updatable views. In practice, when they are needed, updatable views are usually implemented using two separate programs: one that computes the view from the source and another that handles updates. This rudimentary design is tedious for programmers, difcult to reason about, and a nightmare to maintain. This dissertation presents bidirectional programming languages, which provide an elegant and effective mechanism for describing updatable views. Unlike programs written in an ordi- nary language, which only work in one direction, programs in a bidirectional language can be run both forwards and backwards: from left to right, they describe functions that map sources to views, and from right to left, they describe functions that map updated views back to updated sources. Besides eliminating redundancy, these languages can be designed to ensure correctness, guaranteeing by construction that the two functions work well together. Starting from the foundations, we dene a general semantic space of well-behaved bidirec- tional transformations called lenses. Then, building on this foundation, we describe a particu- lar language for dening lenses on strings with syntax based on the familiar regular operators (union, concatenation, and Kleene star). We present extensions to the basic framework that address the subtle complications that arise when lenses are used to manipulate, data containing unimportant details, ordered data, and condential data. iii Acknowledgments Some dissertation projects go like this: the student arrives on campus, the adviser sets a topic, the student disappears into the lab, and emerges several years later with the nished product. Mine, thankfully, has been nothing like this. The work described in this dissertation is the result of an extended, close collaboration with Benjamin Pierce and Alan Schmitt, with additional contributions from Davi Barbosa, Aaron Bohannon, Julien Cretin, Malo Deni´elou, Michael Greenberg, Adam Magee, St´ephane Lescuyer, Danny Puller, Alexandre Pilkiewicz, and Steve Zdancewic. I am lucky to be able to count these talented individuals as my colleagues and friends, and I gratefully acknowledge their contributions to this project. Throughout my time at Penn, my adviser Benjamin Pierce, has always been available to brainstorm about research, crank through a proof, hack on some code, or polish a piece of writing. Thank you Benjamin for setting the standard high, and for encouraging me, nurturing me, and providing help along the way. Zack Ives, Val Tannen, Phil Wadler, and Steve Zdancewic all graciously agreed to serve on my dissertation committee. I wish to thank them for the many hours they spent reading my proposal and this dissertation. Their many insightful comments and valuable suggestions have improved it immensely. Kim Bruce gave me my rst research experience as an undergraduate and told me I would go to graduate school before I even knew I would want to. I am grateful for the opening into the research world he gave me and for close to ten years of guidance. Alan Schmitt helped me navigate the transition to graduate school during the last few months of his postdoc and has continued to be a collaborator, informal mentor, and close friend in the years since. He also hosted me at Rhone-Alpes^ for a productive and extremely enjoyable visit in the spring of 2006. I also wish to thank my mentors Ravi Konuru, J’erome^ iv Sim´eon, and Lionel Villard for an enjoyable internship at IBM Research during the summer of 2007. To the members of Penn’s PLClub and Database Groups, thank you for creating a stimulat- ing and friendly research environment. To my close friends in the department, Colin Blundell, TJ Green, Greg Karvounarakis, Micah Sherr, Nick Taylor, and Svilen Mihaylov, thank you for all the lunch runs, coffee breaks, and pleasant distractions from work. Thanks to my running partners Adam Aviv, John Blitzer, Pavol Cernˇ ´y, and Jeff Vaughan for many miles of good con- versation. To Dimitrios Vytiniotis, it’s been... OK :-) To Mike Felker and Gail Shannon, thank you for solving so many bureaucratic puzzles. The department wouldn’t function without you. To my family, especially Clare, Mollie, Tita Mary, Ahmad, my parents, stepparents, and grandparents thank you for keeping me grounded these past six years and for always believing in me. To Sara, thank you for reminding me how much fun life can be. I’ll meet you for coffee anytime. Philadelphia, PA December 7, 2009 This work was supported in part by an NSF Graduate Research Fellowship and NSF grants CPA-0429836 Harmony: The Art of Reconciliation, IIS-0534592 Linguistic Foundations for XML View Update, and CT-T-0716469 Manifest Security. v Contents 1 Introduction 1 1.1 The View Update Problem ............................. 2 1.2 Bidirectional Programming Languages ....................... 3 1.3 Goal and Contributions .............................. 7 1.4 Acknowledgments .................................. 10 2 Notational Preliminaries 11 2.1 Basic Concepts ................................... 11 2.2 Formal Language Theory .............................. 13 2.3 Regular Languages ................................. 15 3 Basic Lenses 18 3.1 Semantics ...................................... 18 3.2 Basic Lens Properties ................................ 24 3.3 Combinators .................................... 29 3.4 Summary ...................................... 44 4 Quotient Lenses 45 4.1 Semantics ...................................... 48 4.2 Quotient Lens Combinators ............................ 50 4.3 Regular Operators ................................. 59 4.4 Primitives ...................................... 66 4.5 Typechecking ...................................