Book contents
- Frontmatter
- Contents
- Preface to the Second Edition
- Preface
- 1 Standard ML
- 2 Names, Functions and Types
- 3 Lists
- 4 Trees and Concrete Data
- 5 Functions and Infinite Data
- 6 Reasoning About Functional Programs
- 7 Abstract Types and Functors
- 8 Imperative Programming in ML
- 9 Writing Interpreters for the λ-Calculus
- 10 A Tactical Theorem Prover
- Project Suggestions
- Bibliography
- Syntax Charts
- Index
- PREDECLARED IDENTIFIERS
9 - Writing Interpreters for the λ-Calculus
Published online by Cambridge University Press: 05 June 2012
- Frontmatter
- Contents
- Preface to the Second Edition
- Preface
- 1 Standard ML
- 2 Names, Functions and Types
- 3 Lists
- 4 Trees and Concrete Data
- 5 Functions and Infinite Data
- 6 Reasoning About Functional Programs
- 7 Abstract Types and Functors
- 8 Imperative Programming in ML
- 9 Writing Interpreters for the λ-Calculus
- 10 A Tactical Theorem Prover
- Project Suggestions
- Bibliography
- Syntax Charts
- Index
- PREDECLARED IDENTIFIERS
Summary
This chapter brings together all the concepts we have learned so far. For an extended example, it presents a collection of modules to implement the λ-calculus as a primitive functional programming language. Terms of the λ-calculus can be parsed, evaluated and the result displayed. It is hardly a practical language. Trivial arithmetic calculations employ unary notation and take minutes. However, its implementation involves many fundamental techniques: parsing, representing bound variables and reducing expressions to normal form. These techniques can be applied to theorem proving and computer algebra.
Chapter outline
We consider parsing and two interpreters for λ-terms, with an overview of the λ-calculus. The chapter contains the following sections:
A functional parser. An ml functor implements top-down recursive descent parsing. Parsers can be combined using infix operators that resemble the symbols for combining grammatical phrases.
Introducing the λ-calculus. Terms of this calculus can express functional programs. They can be evaluated using either the call-by-value or the call-by-name mechanism. Substitution must be performed carefully, avoiding variable name clashes.
Representing λ-terms inml. Substitution, parsing and pretty printing are implemented as ml structures.
The λ-calculus as a programming language. Typical data structures of functional languages, including infinite lists, are encoded in the λ-calculus. The evaluation of recursive functions is demonstrated.
A functional parser
Before discussing the λ-calculus, let us consider how to write scanners and parsers in a functional style.
- Type
- Chapter
- Information
- ML for the Working Programmer , pp. 357 - 396Publisher: Cambridge University PressPrint publication year: 1996