Typed Tagless Final Interpreters

The so-called ‘typed tagless final' approach of [6] has collected and polished a number of techniques for representing typed higher-order languages in a typed metalanguage, along with type-preserving interpretation, compilation and partial evaluation. The approach is an alternative to the traditional, or ‘initial' encoding of an object language as a (generalized) algebraic data type. Both approaches permit multiple interpretations of an expression, to evaluate it, pretty-print, etc. The final encoding represents all and only typed object terms without resorting to generalized algebraic data types, dependent or other fancy types. The final encoding lets us add new language forms and interpretations without breaking the existing terms and interpreters. These lecture notes introduce the final approach slowly and in detail, highlighting extensibility, the solution to the expression problem, and the seemingly impossible pattern-matching. We develop the approach further, to type-safe cast, run-time-type representation, Dynamics, and type reconstruction. We finish with telling examples of type-directed partial evaluation and encodings of type-and-effect systems and linear lambda-calculus.

[1]  Christian Hofer,et al.  Polymorphic embedding of dsls , 2008, GPCE '08.

[2]  Sophia Mã ¶ ller Partial Evaluation Practice And Theory Diku 1998 International Summer School Copenhagen Denmark June 29 July 10 1998 , 1998 .

[3]  Olivier Danvy Type-Directed Partial Evaluation , 1998, Partial Evaluation.

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

[5]  Stefan Monnier,et al.  A type-preserving compiler in Haskell , 2008, ICFP.

[6]  Bruno C. d. S. Oliveira,et al.  TypeCase: a design pattern for type-indexed functions , 2005, Haskell '05.

[7]  Samuel N. Kamin Final Data Types and Their Specification , 1983, TOPL.

[8]  Peter Thiemann,et al.  Combinators for program generation , 1999, Journal of Functional Programming.

[9]  David Gries Programming Methodology: A Collection of Articles by Members of IFIP WG 2.3 , 1978 .

[10]  John C. Reynolds User-defined types and procedural data structures as complementary approaches to data abstraction , 1994 .

[11]  Gang Chen,et al.  Guarded recursive datatype constructors , 2003, POPL '03.

[12]  Peter Lucas,et al.  Formal Semantics of Programming Languages: VDL , 1981, IBM J. Res. Dev..

[13]  G.D. Plotkin,et al.  LCF Considered as a Programming Language , 1977, Theor. Comput. Sci..

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

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

[16]  Stephanie Weirich,et al.  Type-safe run-time polytypic programming , 2006, Journal of Functional Programming.

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

[18]  James R. Bell,et al.  Threaded code , 1973, CACM.

[19]  G. Winskel The formal semantics of programming languages , 1993 .

[20]  Peter Thiemann,et al.  Tag-Free Combinators for Binding-Time Polymorphic Program Generation , 2010, FLOPS.

[21]  Zhe Yang Encoding types in ML-like languages , 2004, Theor. Comput. Sci..

[22]  Riccardo Pucella,et al.  Phantom types and subtyping , 2002, Journal of Functional Programming.

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

[24]  Mitchell Wand,et al.  Final Algebra Semantics and Data Type Extensions , 1979, J. Comput. Syst. Sci..

[25]  Olivier Danvy,et al.  Representing Control: a Study of the CPS Transformation , 1992, Mathematical Structures in Computer Science.

[26]  S. Doaitse Swierstra,et al.  Typing dynamic typing , 2002, ICFP '02.

[27]  Sam Lindley,et al.  Extensional Rewriting with Sums , 2007, TLCA.

[28]  Olivier Danvy Functional Unparsing , 1998, J. Funct. Program..

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

[30]  Ralf Hinze Formatting: a class act , 2003, J. Funct. Program..

[31]  Jacques Garrigue,et al.  Code reuse through polymorphic variants , 2000 .

[32]  Kenichi Asai On typing delimited continuations: three new solutions to the printf problem , 2009, High. Order Symb. Comput..

[33]  Corrado Böhm,et al.  Automatic Synthesis of Typed Lambda-Programs on Term Algebras , 1985, Theor. Comput. Sci..

[34]  Glynn Winskel,et al.  The formal semantics of programming languages - an introduction , 1993, Foundation of computing series.

[35]  Walid Taha,et al.  Tagless staged interpreters for typed languages , 2002, ICFP '02.

[36]  John C. Mitchell,et al.  Theoretical aspects of object-oriented programming: types, semantics, and language design , 1994, Choice Reviews Online.

[37]  Simon L. Peyton Jones,et al.  Type classes in Haskell , 1994, TOPL.

[38]  Brian Campbell,et al.  Amortised Memory Analysis Using the Depth of Data Structures , 2009, ESOP.

[39]  Paul Hudak,et al.  Building domain-specific embedded languages , 1996, CSUR.

[40]  Gopalan Nadathur,et al.  A Logic Programming Approach to Manipulating Formulas and Programs , 1987, SLP.

[41]  Alonzo Church,et al.  A formulation of the simple theory of types , 1940, Journal of Symbolic Logic.

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

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

[44]  Sebastian Fischer,et al.  Purely functional lazy non-deterministic programming , 2009, Journal of Functional Programming.

[45]  Stephanie Weirich,et al.  Encoding Intensional Type Analysis , 2001, ESOP.

[46]  Frank Pfenning,et al.  Eliminating array bound checking through dependent types , 1998, PLDI.