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
5 - Functions and Infinite Data
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
The most powerful techniques of functional programming are those that treat functions as data. Most functional languages give function values full rights, free of arbitrary restrictions. Like other values, functions may be arguments and results of other functions and may belong to pairs, lists and trees.
Procedural languages like Fortran and Pascal accept this idea as far as is convenient for the compiler writer. Functions may be arguments: say, the comparison to be used in sorting or a numerical function to be integrated. Even this restricted case is important.
A function is higher-order (or a functional) if it operates on other functions. For instance, the functional map applies a function to every element of a list, creating a new list. A sufficiently rich collection of functionals can express all functions without using variables. Functionals can be designed to construct parsers (see Chapter 9) and theorem proving strategies (see Chapter 10).
Infinite lists, whose elements are evaluated upon demand, can be implemented using functions as data. The tail of a lazy list is a function that, if called, produces another lazy list. A lazy list can be infinitely long and any finite number of its elements can be evaluated.
Chapter outline
The first half presents the essential programming techniques involving functions as data. The second half serves as an extended, practical example. Lazy lists can be represented in ml (despite its strict evaluation rule) by means of function values.
- Type
- Chapter
- Information
- ML for the Working Programmer , pp. 171 - 212Publisher: Cambridge University PressPrint publication year: 1996