Functional pearl: i am not a number--i am a free variable

In this paper, we show how to manipulate syntax with binding using a mixed representation of names for free variables (with respect to the task in hand) and de Bruijn indices [5] for bound variables. By doing so, we retain the advantages of both representations: naming supports easy, arithmetic-free manipulation of terms; de Bruijn indices eliminate the need for α-conversion. Further, we have ensured that not only the user but also the implementation need never deal with de Bruijn indices, except within key basic operations.Moreover, we give a hierarchical representation for names which naturally reflects the structure of the operations we implement. Name choice is safe and straightforward. Our technology combines easily with an approach to syntax manipulation inspired by Huet's 'zippers'[10].Without the ideas in this paper, we would have struggled to implement EPIGRAM [19]. Our example-constructing inductive elimination operators for datatype families-is but one of many where it proves invaluable.

[1]  F. Saussure,et al.  Course in General Linguistics , 1960 .

[2]  D. Prawitz Natural Deduction: A Proof-Theoretical Study , 1965 .

[3]  James Hook,et al.  Substitution: A Formal Methods Case Study Using Monads and Transformations , 1994, Sci. Comput. Program..

[4]  S. C. Kleene,et al.  Introduction to Metamathematics , 1952 .

[5]  Philip Wadler,et al.  Packrat parsing:: simple, powerful, lazy, linear time, functional pearl , 2002, ICFP '02.

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

[7]  James McKinna,et al.  Some Lambda Calculus and Type Theory Formalized , 1997, Journal of Automated Reasoning.

[8]  Gérard P. Huet,et al.  The Constructive Engine , 1989, A Perspective in Theoretical Computer Science.

[9]  Conor McBride,et al.  Inverting Inductively Defined Relations in LEGO , 1996, TYPES.

[10]  Dale Miller,et al.  Unification Under a Mixed Prefix , 1992, J. Symb. Comput..

[11]  Thorsten Altenkirch,et al.  Monadic Presentations of Lambda Terms Using Generalized Inductive Types , 1999, CSL.

[12]  Thomas Johnsson,et al.  Lambda Lifting: Treansforming Programs to Recursive Equations , 1985, FPCA.

[13]  P. Medawar A view from the left , 1984, Nature.

[14]  Gift Siromoney,et al.  A Perspective in Theoretical Computer Science - Commemorative Volume for Gift Siromoney , 1989, A Perspective in Theoretical Computer Science.

[15]  T. Coquand An algorithm for testing conversion in type theory , 1991 .

[16]  Zhaohui Luo,et al.  Computation and reasoning - a type theory for computer science , 1994, International series of monographs on computer science.

[17]  Randy Pollack,et al.  Closure Under Alpha-Conversion , 1994, TYPES.

[18]  Conor McBride,et al.  Elimination with a Motive , 2000, TYPES.

[19]  Gérard P. Huet,et al.  The Zipper , 1997, Journal of Functional Programming.

[20]  Joyce L. Vedral,et al.  Functional Programming Languages and Computer Architecture , 1989, Lecture Notes in Computer Science.

[21]  de Ng Dick Bruijn,et al.  Lambda calculus notation with nameless dummies, a tool for automatic formula manipulation, with application to the Church-Rosser theorem , 1972 .

[22]  Gordon D. Plotkin,et al.  Logical frameworks , 1991 .

[23]  James McKinna,et al.  Pure Type Systems Formalized , 1993, TLCA.

[24]  J. Davenport Editor , 1960 .

[25]  M. E. Szabo,et al.  The collected papers of Gerhard Gentzen , 1969 .

[26]  Richard S. Bird,et al.  de Bruijn notation as a nested datatype , 1999, Journal of Functional Programming.