Embedding invertible languages with binders: a case of the FliPpr language

This paper describes a new embedding technique of invertible programming languages, through the case of the FliPpr language. Embedded languages have the advantage of inheriting host languages' features and supports; and one of the influential methods of embedding is the tagless-final style, which enables a high level of programmability and extensibility. However, it is not straightforward to apply the method to the family of invertible/reversible/bidirectional languages, due to the different ways functions in such domains are represented. We consider FliPpr, an invertible pretty-printing system, as a representative of such languages, and show that Atkey et al.'s unembedding technique can be used to address the problem. Together with a reformulation of FliPpr, our embedding achieves a high level of interoperability with the host language Haskell, which is not found in any other invertible languages. We implement the idea and demonstrate the benefits of the approach with examples.

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

[2]  Robert Atkey Syntax for Free: Representing Syntax with Binding Using Parametricity , 2009, TLCA.

[3]  Jacques Carette,et al.  Finally tagless, partially evaluated: Tagless staged interpreters for simpler typed languages , 2007, Journal of Functional Programming.

[4]  Meng Wang,et al.  Applicative bidirectional programming with lenses , 2015, ICFP.

[5]  Richard A. Frost,et al.  Parser Combinators for Ambiguous Left-Recursive Grammars , 2008, PADL.

[6]  Robert Glück,et al.  Towards a Reversible Functional Language , 2011, RC.

[7]  Oleg Kiselyov,et al.  Probabilistic Programming Language and its Incremental Evaluation , 2016, APLAS.

[8]  Meng Wang,et al.  HOBiT: Programming Lenses Without Using Lens Combinators , 2018, ESOP.

[9]  Ross Paterson,et al.  A new notation for arrows , 2001, ICFP '01.

[10]  Tetsuo Yokoyama,et al.  Reversible Computation and Reversible Programming Languages , 2010, RC@ETAPS.

[11]  Klaus Ostermann,et al.  Invertible syntax descriptions: unifying parsing and pretty printing , 2010 .

[12]  Adam Chlipala Parametric higher-order abstract syntax for mechanized semantics , 2008, ICFP.

[13]  Kazutaka Matsuda,et al.  A functional reformulation of UnCAL graph-transformations: or, graph transformation as graph reduction , 2017, PEPM.

[14]  Meng Wang,et al.  Applicative bidirectional programming: Mixing lenses and semantic bidirectionalization , 2018, J. Funct. Program..

[15]  S. Doaitse Swierstra,et al.  Typed Transformations of Typed Grammars: The Left Corner Transform , 2010, Electron. Notes Theor. Comput. Sci..

[16]  Philip Wadler,et al.  A prettier printer , 2002 .

[17]  Robert Glück,et al.  Derivation of Deterministic Inverse Programs Based on LR Parsing , 2004, FLOPS.

[18]  Loris D'Antoni,et al.  Automatic program inversion using symbolic transducers , 2017, PLDI.

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

[20]  Kazutaka Matsuda,et al.  Polynomial-time inverse computation for accumulative functions with multiple data traversals , 2012, PEPM '12.

[21]  Kazutaka Matsuda,et al.  Polynomial-time inverse computation for accumulative functions with multiple data traversals , 2012 .

[22]  Nils Anders Danielsson Correct-by-construction pretty-printing , 2013, DTP '13.

[23]  Koen Claessen,et al.  QuickCheck: a lightweight tool for random testing of Haskell programs , 2011, SIGP.

[24]  Meng Wang,et al.  FliPpr: A Prettier Invertible Printing System , 2013, ESOP.

[25]  Philip Wadler,et al.  Deforestation: Transforming Programs to Eliminate Trees , 1988, Theoretical Computer Science.

[26]  Alcino Cunha,et al.  Generic Point-free Lenses , 2010, MPC.

[27]  Sebastian Fischer,et al.  Purely functional lazy nondeterministic programming , 2011, J. Funct. Program..

[28]  Robert Atkey,et al.  Unembedding domain-specific languages , 2009, Haskell.

[29]  Patrik Jansson,et al.  Embedded parser generators , 2012 .

[30]  Graham Hutton,et al.  Higher-order functions for parsing , 1992, Journal of Functional Programming.

[31]  Masahiko Sakai,et al.  Generation of Inverse Term Rewriting Systems for Pure Treeless Functions , 2001 .

[32]  Jeff Polakow Embedding a full linear Lambda calculus in Haskell , 2015, Haskell.

[33]  Johan Jeuring,et al.  Generic conversions of abstract syntax representations , 2012, WGP '12.

[34]  Robert Glück,et al.  Revisiting an automatic program inverter for Lisp , 2005, SIGP.

[35]  Shin-Cheng Mu,et al.  A Grammar-Based Approach to Invertible Programs , 2010, ESOP.

[36]  Zhenjiang Hu,et al.  Monadic combinators for "Putback" style bidirectional programming , 2014, PEPM '14.

[37]  Fritz Henglein,et al.  Type inference with polymorphic recursion , 1993, TOPL.

[38]  John Hughes,et al.  Generalising monads to arrows , 2000, Sci. Comput. Program..

[39]  John Hughes,et al.  The Design of a Pretty-printing Library , 1995, Advanced Functional Programming.