Everybody's Got To Be Somewhere

The key to any nameless representation of syntax is how it indicates the variables we choose to use and thus, implicitly, those we discard. Standard de Bruijn representations delay discarding maximally till the leaves of terms where one is chosen from the variables in scope at the expense of the rest. Consequently, introducing new but unused variables requires term traversal. This paper introduces a nameless 'co-de-Bruijn' representation which makes the opposite canonical choice, delaying discarding minimally, as near as possible to the root. It is literate Agda: dependent types make it a practical joy to express and be driven by strong intrinsic invariants which ensure that scope is aggressively whittled down to just the support of each subterm, in which every remaining variable occurs somewhere. The construction is generic, delivering a universe of syntaxes with higher-order metavariables, for which the appropriate notion of substitution is hereditary. The implementation of simultaneous substitution exploits tight scope control to avoid busywork and shift terms without traversal. Surprisingly, it is also intrinsically terminating, by structural recursion alone.

[1]  Jeremy Gibbons,et al.  APLicative Programming with Naperian Functors , 2017, ESOP.

[2]  Ian Mackie,et al.  Efficient Reductions with Director Strings , 2003, RTA.

[3]  Conor McBride First-order unification by structural recursion , 2003, J. Funct. Program..

[4]  David Walker,et al.  A Concurrent Logical Framework: The Propositional Fragment , 2003, TYPES.

[5]  Thorsten Altenkirch,et al.  Hereditary substitutions for simple types, formalized , 2010, MSFP '10.

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

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

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

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

[10]  Helmut Schwichtenberg,et al.  Viewing λ-terms through maps , 2013 .

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

[12]  Ulf Norell,et al.  Dependently typed programming in Agda , 2009, TLDI '09.

[13]  Andreas Abel,et al.  A Lambda Term Representation Inspired by Linear Ordered Logic , 2011, LFMTP.

[14]  Richard Kennaway,et al.  Variable Abstraction in O(n log n) Space , 1987, Inf. Process. Lett..

[15]  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 .

[16]  Conor McBride,et al.  Type-and-scope safe programs and their proofs , 2017, CPP.

[17]  Chung-Kil Hur,et al.  Strongly Typed Term Representations in Coq , 2011, Journal of Automated Reasoning.

[18]  Martin Hofmann,et al.  Categorical Reconstruction of a Reduction Free Normalization Proof , 1995, Category Theory and Computer Science.

[19]  Conor McBride,et al.  Dependently typed functional programs and their proofs , 2000 .

[20]  Andreas Abel Implementing a normalizer using sized heterogeneous types , 2006, J. Funct. Program..