On Type-directed Generation of Lambda Terms

We describe a Prolog-based combined lambda term generator and type-inferrer for closed well-typed terms of a given size, in de Bruijn notation. By taking advantage of Prolog’s unique bidirectional execution model and sound unification algorithm, our generator can build “customized” closed terms of a given type. This relational view of terms and their types enables the discovery of interesting patterns about frequently used type expressions occurring in well-typed functional programs. Our study uncovers the most “popular” types that govern function applications among a about a million small-sized lambda terms and hints toward practical uses to combinatorial software testing. It also shows the effectiveness of Prolog as a meta-language for modeling properties of lambda terms and their types.

[1]  Paul Tarau On Logic Programming Representations of Lambda Terms: de Bruijn Indices, Compression, Type Inference, Combinatorial Generation, Normalization , 2015, PADL.

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

[3]  E. M. Rijke,et al.  Homotopy type theory , 2012 .

[4]  Richard Statman,et al.  Lambda Calculus with Types , 2013, Perspectives in logic.

[5]  Paul Tarau,et al.  On a uniform representation of combinators, arithmetic, lambda terms and types , 2015, PPDP.

[6]  Christophe Raffalli,et al.  Asymptotically almost all \lambda-terms are strongly normalizing , 2009 .

[7]  Fairouz Kamareddine,et al.  Reviewing the Classical and the de Bruijn Notation for [lambda]-calculus and Pure Type Systems , 2001, J. Log. Comput..

[8]  René David,et al.  Some properties of random lambda terms , 2009, Log. Methods Comput. Sci..

[9]  Henk Barendregt,et al.  The Lambda Calculus: Its Syntax and Semantics , 1985 .

[10]  Pawel M. Idziak,et al.  How big is BCI fragment of BCK logic , 2013, J. Log. Comput..

[11]  Koen Claessen,et al.  Making Random Judgments: Automatically Generating Well-Typed Terms from the Definition of a Type-System , 2015, ESOP.

[12]  P. H. Testing an Optimising Compiler by Generating Random Lambda Terms , 2012 .

[13]  N. J. A. Sloane,et al.  The On-Line Encyclopedia of Integer Sequences , 2003, Electron. J. Comb..

[14]  Jeroen D. Fokker,et al.  The systematic construction of a one-combinator basis for Lambda-Terms , 1992, Formal Aspects of Computing.

[15]  J. Roger Hindley,et al.  Lambda-Calculus and Combinators: An Introduction , 2008 .

[16]  Danièle Gardy,et al.  Lambda-terms of Bounded Unary Height , 2011, ANALCO.

[17]  Pierre Lescanne,et al.  Counting and generating lambda terms , 2012, Journal of Functional Programming.

[18]  Steven Awodey,et al.  Homotopy Type Theory , 2015, ICLA.