Parametric Compositional Data Types

In previous work we have illustrated the benefits that compositional data types (CDTs) offer for implementing languages and in general for dealing with abstract syntax trees (ASTs). Based on Swierstra's data types \'a la carte, CDTs are implemented as a Haskell library that enables the definition of recursive data types and functions on them in a modular and extendable fashion. Although CDTs provide a powerful tool for analysing and manipulating ASTs, they lack a convenient representation of variable binders. In this paper we remedy this deficiency by combining the framework of CDTs with Chlipala's parametric higher-order abstract syntax (PHOAS). We show how a generalisation from functors to difunctors enables us to capture PHOAS while still maintaining the features of the original implementation of CDTs, in particular its modularity. Unlike previous approaches, we avoid so-called exotic terms without resorting to abstract types: this is crucial when we want to perform transformations on CDTs that inspect the recursively computed CDTs, e.g. constant folding.

[1]  Simon Marlow,et al.  Haskell 2010 Language Report , 2010 .

[2]  Apostolos Syropoulos,et al.  Steps in Scala: The expression problem , 2010 .

[3]  Stephanie Weirich,et al.  Boxes go bananas: encoding higher-order abstract syntax with parametric polymorphism , 2003, ICFP '03.

[4]  Andrew M. Pitts,et al.  FreshML: programming with binders made simple , 2003, ICFP '03.

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

[6]  Simon Peyton Jones,et al.  Type checking with open type functions , 2008, ICFP 2008.

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

[8]  Wouter Swierstra,et al.  Data types à la carte , 2008, Journal of Functional Programming.

[9]  Simon L. Peyton Jones,et al.  Complete and decidable type inference for GADTs , 2009, ICFP.

[10]  Andrew M. Pitts,et al.  Alpha-structural recursion and induction , 2005, JACM.

[11]  Philip Wadler,et al.  Deforestation: Transforming Programs to Eliminate Trees , 1990, Theor. Comput. Sci..

[12]  Patrick Bahr,et al.  Compositional data types , 2011, WGP@ICFP.

[13]  Maarten M. Fokkinga Monadic Maps and Folds for Arbitrary Datatypes , 1994 .

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

[15]  Hubert Comon,et al.  Tree automata techniques and applications , 1997 .

[16]  Simon L. Peyton Jones,et al.  Template meta-programming for Haskell , 2002, Haskell '02.

[17]  Tim Sheard,et al.  Revisiting catamorphisms over datatypes with embedded functions (or, programs from outer space) , 1996, POPL '96.

[18]  Simon Peyton Jones,et al.  Playing by the rules: rewriting as a practical optimisation technique in GHC , 2001 .

[19]  Simon L. Peyton Jones,et al.  Type checking with open type functions , 2008, ICFP.

[20]  Patricia Johann,et al.  Foundations for structured programming with GADTs , 2008, POPL '08.

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

[22]  Tim Sheard,et al.  A hierarchy of mendler style recursion combinators: taming inductive datatypes with negative occurrences , 2011, ICFP '11.

[23]  Graham Hutton,et al.  Bananas in space: extending fold and unfold to exponential types , 1995, FPCA '95.

[24]  Frank Pfenning,et al.  Higher-order abstract syntax , 1988, PLDI '88.

[25]  Maarten M. Fokkinga,et al.  Functional Programming with Bananas, Lenses, Envelopes and Barbed Wire , 1991, FPCA.

[26]  Frank Pfenning,et al.  Primitive recursion for higher-order abstract syntax , 1997, Theor. Comput. Sci..