Tagless staged interpreters for typed languages

Multi-stage programming languages provide a convenient notation for explicitly staging programs. Staging a definitional interpreter for a domain specific language is one way of deriving an implementation that is both readable and efficient. In an untyped setting, staging an interpreter "removes a complete layer of interpretive overhead", just like partial evaluation. In a typed setting however, Hindley-Milner type systems do not allow us to exploit typing information in the language being interpreted. In practice, this can mean a slowdown cost by a factor of three or mor.Previously, both type specialization and tag elimination were applied to this problem. In this paper we propose an alternative approach, namely, expressing the definitional interpreter in a dependently typed programming language. We report on our experience with the issues that arise in writing such an interpreter and in designing such a language. .To demonstrate the soundness of combining staging and dependent types in a general sense, we formalize our language (called Meta-D) and prove its type safety. To formalize Meta-D, we extend Shao, Saha, Trifonov and Papaspyrou's λH language to a multi-level setting. Building on λH allows us to demonstrate type safety in a setting where the type language contains all the calculus of inductive constructions, but without having to repeat the work needed for establishing the soundness of that system.

[1]  Peter Dybjer,et al.  Finite Axiomatizations of Inductive and Inductive-Recursive Definitions , 1998 .

[2]  Peter Dybjer,et al.  A general formulation of simultaneous inductive-recursive definitions in type theory , 2000, Journal of Symbolic Logic.

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

[4]  Paul Hudak,et al.  Directions in Functional Programming for Real(-Time) Applications , 2001, EMSOFT.

[5]  Walid Taha,et al.  Multi-Stage Programming: Its Theory and Applications , 1999 .

[6]  Carl A. Gunter Semantics of programming languages: structures and techniques , 1993, Choice Reviews Online.

[7]  Zhong Shao,et al.  A type system for certi .ed binaries , 2002, Foundations of Intrusion Tolerant Systems, 2003 [Organically Assured and Survivable Information Systems].

[8]  Magnus Carlsson,et al.  An exercise in dependent types: A well-typed interpreter , 1999 .

[9]  Frank Pfenning,et al.  Dependent types in practical programming , 1999, POPL '99.

[10]  Jon Louis Bentley,et al.  Programming pearls: little languages , 1986, CACM.

[11]  Bengt Nordström,et al.  Programming in Martin-Löf's Type Theory , 1990 .

[12]  Karl Crary,et al.  Intensional polymorphism in type-erasure semantics , 2002, J. Funct. Program..

[13]  Torben Æ. Mogensen Inherited limits , 1998, CSUR.

[14]  Peter Lee,et al.  LEAP: A Language with Eval And Polymorphism , 1989, TAPSOFT, Vol.2.

[15]  ShaoZhong,et al.  Fully reflexive intensional type analysis , 2000 .

[16]  Bengt Nordström,et al.  Programming in Constructive Set Theory: Some examples , 1981, FPCA '81.

[17]  Calton Pu,et al.  Microlanguages for Operating System Specialization , 1997 .

[18]  Walid Taha Semantics, Applications, and Implementation of Program Generation , 2003, J. Funct. Program..

[19]  Simon L. Peyton Jones,et al.  Dynamic typing as staged type inference , 1998, POPL '98.

[20]  Paul Hudak,et al.  Modular domain specific languages and tools , 1998, Proceedings. Fifth International Conference on Software Reuse (Cat. No.98TB100203).

[21]  Karl Crary,et al.  Resource bound certification , 2000, POPL '00.

[22]  Yannis Smaragdakis,et al.  DiSTiL: A Transformation Library for Data Structures , 1997, DSL.

[23]  Walid Taha,et al.  Tag Elimination - or - Type Specialisation is a Type-Indexed Effect , 2000 .

[24]  Robert D. Tennent,et al.  Semantics of programming languages , 1991, Prentice Hall International Series in Computer Science.

[25]  Amr Sabry,et al.  Proving the correctness of reactive systems using sized types , 1996, POPL '96.

[26]  P. Dybjer Inductive sets and families in Martin-Lo¨f's type theory and their set-theoretic semantics , 1991 .

[27]  Zhong Shao,et al.  Fully reflexive intensional type analysis , 2000, ICFP '00.

[28]  Christine Paulin-Mohring,et al.  Inductive Definitions in the system Coq - Rules and Properties , 1993, TLCA.

[29]  Thierry Coquand,et al.  Type Theorie Programming , 1994, Bull. EATCS.

[30]  Emir Pasalic,et al.  DSL implementation using staging and monads , 1999, DSL '99.

[31]  Peter Sestoft,et al.  Partial evaluation and automatic program generation , 1993, Prentice Hall international series in computer science.

[32]  John C. Reynolds,et al.  Definitional Interpreters for Higher-Order Programming Languages , 1972, ACM '72.

[33]  Eduardo Giménez,et al.  A Tutorial on Recursive Types in Coq , 1998 .

[34]  Walid Taha,et al.  Semantics, Applications, and Implementation of Program Generation , 2001, Lecture Notes in Computer Science.

[35]  HudakPaul Building domain-specific embedded languages , 1996 .

[36]  Walid Taha,et al.  Tag Elimination and Jones-Optimality , 2001, PADO.

[37]  Henning Makholm,et al.  On Jones-Optimal Specialization for Strongly Typed Languages , 2000, SAIG.

[38]  Walid Taha,et al.  An Idealized MetaML: Simpler, and More Expressive , 1999, ESOP.

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

[40]  Walid Taha,et al.  Multi-stage programming with explicit annotations , 1997 .

[41]  Torben Æ. Mogensen,et al.  Partial Evaluation. Practice and Theory: DIKU 1998 International Summer School, Copenhagen, Denmark, June 29 - July 10, 1998 , 1998 .

[42]  Luca Cardelli,et al.  Phase Distinctions in Type Theory , 1988 .

[43]  Furio Honsell,et al.  A framework for defining logics , 1993, JACM.

[44]  John C. Reynolds Definitional Interpreters for Higher-Order Programming Languages , 1998, High. Order Symb. Comput..

[45]  Matthias Felleisen,et al.  A Syntactic Approach to Type Soundness , 1994, Inf. Comput..

[46]  Andrew W. Appel,et al.  A type-based compiler for standard ML , 1995, PLDI '95.

[47]  Robert Harper,et al.  Compiling polymorphism using intensional type analysis , 1995, POPL '95.

[48]  Walid Taha,et al.  A sound reduction semantics for untyped CBN mutli-stage computation. Or, the theory of MetaML is non-trival (extended abstract) , 1999, PEPM '00.

[49]  Frank Pfenning,et al.  A language with eval and polymorphism , 1989 .

[50]  Benjamin C. Peirce,et al.  Basic Category Theory for Computer Scientists , 1991 .

[51]  Walid Taha A sound reduction semantics for untyped CBN multi-stage computation. Or, the theory of MetaML is non-trivial (preliminary Report) , 1999 .

[52]  Walid Taha,et al.  Multi-Stage Programming: Axiomatization and Type Safety , 1998, ICALP.

[53]  SheardTim,et al.  Tagless staged interpreters for typed languages , 2002 .

[54]  F. Pfenning Logic programming in the LF logical framework , 1991 .

[55]  Karl Crary,et al.  Flexible type analysis , 1999, ICFP '99.