A type-theoretic foundation for programming with higher-order abstract syntax and first-class substitutions

Higher-order abstract syntax (HOAS) is a simple, powerful technique for implementing object languages, since it directly supports common and tricky routines dealing with variables, such as capture-avoiding substitution and renaming. This is achieved by representing binders in the object-language via binders in the meta-language. However, enriching functional programming languages with direct support for HOAS has been a major challenge, because recursion over HOAS encodings requires one to traverse lambda-abstractions and necessitates programming with open objects. We present a novel type-theoretic foundation based on contextual modal types which allows us to recursively analyze open terms via higher-order pattern matching. By design, variables occurring in open terms can never escape their scope. Using several examples, we demonstrate that our framework provides a name-safe foundation to operations typically found in nominal systems. In contrast to nominal systems however, we also support capture-avoiding substitution operations and even provide first-class substitutions to the programmer. The main contribution of this paper is a syntax-directed bi-directional type system where we distinguish between the data language and the computation language together with the progress and preservation proof for our language.

[1]  François Pottier,et al.  Static Name Control for FreshML , 2007, 22nd Annual IEEE Symposium on Logic in Computer Science (LICS 2007).

[2]  Dale Miller,et al.  An Extension to ML to Handle Bound Variables in Data Structures: Preliminary Report , 1990 .

[3]  Frank Pfenning,et al.  Tabled higher-order logic programming , 2003 .

[4]  Carsten Schürmann,et al.  The ∇-Calculus. Functional Programming with Higher-Order Encodings , 2004 .

[5]  Kwangkeun Yi,et al.  A polymorphic modal type system for lisp-like multi-staged languages , 2006, POPL '06.

[6]  Stefan Monnier,et al.  Statically Verified Type-Preserving Code Transformations in Haskell , 2006 .

[7]  Andrew M. Pitts,et al.  A new approach to abstract syntax involving binders , 1999, Proceedings. 14th Symposium on Logic in Computer Science (Cat. No. PR00158).

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

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

[10]  Guillermo E. Herrera Automating the meta theory of deductive systems , 2000 .

[11]  Frank Pfenning,et al.  Contextual modal type theory , 2008, TOCL.

[12]  Shin-ya Nishizaki,et al.  A Polymorphic Environment Calculus and its Type-Inference Algorithm , 2000, High. Order Symb. Comput..

[13]  Frank Pfenning,et al.  System Description: Twelf - A Meta-Logical Framework for Deductive Systems , 1999, CADE.

[14]  Patrick Baillot,et al.  Elementary Complexity and Geometry of Interaction , 1999, Fundam. Informaticae.

[15]  Frank Pfenning,et al.  A Coverage Checking Algorithm for LF , 2003, TPHOLs.

[16]  Atsushi Ohori,et al.  A typed context calculus , 2001, Theor. Comput. Sci..

[17]  Ian A. Mason Computing with Contexts , 1999, High. Order Symb. Comput..

[18]  Rod M. Burstall,et al.  Explicit Environments , 1999, Fundam. Informaticae.

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

[20]  Martín Abadi,et al.  Explicit substitutions , 1989, POPL '90.

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

[22]  D. Walker,et al.  A concurrent logical framework I: Judgments and properties , 2003 .

[23]  Frank Pfenning,et al.  Optimizing Higher-Order Pattern Unification , 2003, CADE.

[24]  Yukiyoshi Kameyama,et al.  A Simply Typed Context Calculus with First-class Environments , 2001, J. Funct. Log. Program..

[25]  Andrew McCreight,et al.  A Meta Linear Logical Framework , 2008, Electron. Notes Theor. Comput. Sci..

[26]  Dale Miller,et al.  Unification of Simply Typed Lamda-Terms as Logic Programming , 1991, ICLP.