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
3 - Lists
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
In a public lecture, C. A. R. Hoare (1989a) described his algorithm for finding the ith smallest integer in a collection. This algorithm is subtle, but Hoare described it with admirable clarity as a game of solitaire. Each playing card carried an integer. Moving cards from pile to pile by simple rules, the required integer could quickly be found.
Then Hoare changed the rules of the game. Each card occupied a fixed position, and could only be moved if exchanged with another card. This described the algorithm in terms of arrays. Arrays have great efficiency, but they also have a cost. They probably defeated much of the audience, as they defeat experienced programmers. Mills and Linger (1986) claim that programmers become more productive when arrays are restricted to stacks, queues, etc., without subscripting.
Functional programmers often process collections of items using lists. Like Hoare's stacks of cards, lists allow items to be dealt with one at a time, with great clarity. Lists are easy to understand mathematically, and turn out to be more efficient than commonly thought.
Chapter outline
This chapter describes how to program with lists in Standard ml. It presents several examples that would normally involve arrays, such as matrix operations and sorting.
The chapter contains the following sections:
Introduction to lists. The notion of list is introduced. Standard ml operates on lists using pattern-matching.
- Type
- Chapter
- Information
- ML for the Working Programmer , pp. 69 - 122Publisher: Cambridge University PressPrint publication year: 1996