Ur: statically-typed metaprogramming with type-level record computation

Dependent types provide a strong foundation for specifying and verifying rich properties of programs through type-checking. The earliest implementations combined dependency, which allows types to mention program variables; with type-level computation, which facilitates expressive specifications that compute with recursive functions over types. While many recent applications of dependent types omit the latter facility, we argue in this paper that it deserves more attention, even when implemented without dependency. In particular, the ability to use functional programs as specifications enables statically-typed metaprogramming: programs write programs, and static type-checking guarantees that the generating process never produces invalid code. Since our focus is on generic validity properties rather than full correctness verification, it is possible to engineer type inference systems that are very effective in narrow domains. As a demonstration, we present Ur, a programming language designed to facilitate metaprogramming with first-class records and names. On top of Ur, we implement Ur/Web, a special standard library that enables the development of modern Web applications. Ad-hoc code generation is already in wide use in the popular Web application frameworks, and we show how that generation may be tamed using types, without forcing metaprogram authors to write proofs or forcing metaprogram users to write any fancy types.

[1]  Benjamin C. Pierce Higher-Order Polymorphism , 2002 .

[2]  David Watson,et al.  Web App Attacks: Web application attacks , 2007 .

[3]  Benjamin C. Pierce,et al.  A record calculus based on symmetric concatenation , 1991, POPL '91.

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

[5]  Yves Bertot,et al.  Interactive Theorem Proving and Program Development: Coq'Art The Calculus of Inductive Constructions , 2010 .

[6]  Shan Shan Huang,et al.  Expressive and safe static reflection with MorphJ , 2008, PLDI '08.

[7]  Zhong Shao,et al.  Implementing typed intermediate languages , 1998, ICFP '98.

[8]  Daan Leijen,et al.  Domain specific embedded compilers , 1999, DSL '99.

[9]  James R. Larus,et al.  Reflective program generation with patterns , 2006, GPCE '06.

[10]  Frank Pfenning,et al.  Partial polymorphic type inference and higher-order unification , 1988, LISP and Functional Programming.

[11]  David B. MacQueen Modules for standard ML , 1984, LFP '84.

[12]  Alexandra Silva,et al.  Strong types for relational databases , 2006, Haskell '06.

[13]  U. Norell,et al.  Towards a practical programming language based on dependent type theory , 2007 .

[14]  Lennart Augustsson,et al.  Cayenne—a language with dependent types , 1998, ICFP '98.

[15]  George C. Necula,et al.  Dependent Types for Low-Level Programming , 2007, ESOP.

[16]  Didier Rémy,et al.  Type inference for records in natural extension of ML , 1994 .

[17]  Tim Sheard Languages of the future , 2004, ACM SIGPLAN Notices.

[18]  Patrick Maxim Rondon,et al.  Liquid types , 2008, PLDI '08.

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

[20]  Mitchell Wand,et al.  Type inference for record concatenation and multiple inheritance , 1989, [1989] Proceedings. Fourth Annual Symposium on Logic in Computer Science.

[21]  Umut A. Acar,et al.  Extensible programming with first-class cases , 2006, ICFP '06.

[22]  Pierre Castéran,et al.  Interactive Theorem Proving and Program Development , 2004, Texts in Theoretical Computer Science An EATCS Series.

[23]  Hongwei Xi,et al.  Dependent ML An approach to practical programming with dependent types , 2007, Journal of Functional Programming.

[24]  Mark P. Jones,et al.  Type Classes with Functional Dependencies , 2000, ESOP.

[25]  Stephen N. Freund,et al.  Sage: Unified Hybrid Checking for First-Class Types, General Refinement Types, and Dynamic (Extended Report) , 2007 .

[26]  Ralf Lämmel,et al.  Strongly typed heterogeneous collections , 2004, Haskell '04.

[27]  Joe B. Wells,et al.  Typability and Type Checking in System F are Equivalent and Undecidable , 1999, Ann. Pure Appl. Log..

[28]  François Pottier,et al.  A 3-Part Type Inference Engine , 2000, ESOP.

[29]  Chiyan Chen,et al.  Combining programming with theorem proving , 2005, ICFP '05.

[30]  Peter Buneman,et al.  Type inference in a database programming language , 1988, LISP and Functional Programming.

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

[32]  Benedict R. Gaster,et al.  A Polymorphic Type System for Extensible Records and Variants , 1996 .

[33]  Roy L. Crole Higher Order Polymorphism , 1994 .

[34]  Thorsten Altenkirch,et al.  Generic Programming within Dependently Typed Programming , 2002, Generic Programming.

[35]  Atsushi Ohori,et al.  A polymorphic record calculus and its compilation , 1995, TOPL.