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
7 - Abstract Types and Functors
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
Everyone accepts that large programs should be organized as hierarchical modules. Standard ml's structures and signatures meet this requirement. Structures let us package up declarations of related types, values and functions. Signatures let us specify what components a structure must contain. Using structures and signatures in their simplest form we have treated examples ranging from the complex numbers in Chapter 2 to infinite sequences in Chapter 5.
A modular structure makes a program easier to understand. Better still, the modules ought to serve as interchangeable parts: replacing one module by an improved version should not require changing the rest of the program. Standard ml'sabstract types and functors can help us meet this objective too.
A module may reveal its internal details. When the module is replaced, other parts of the program that depend upon such details will fail. ml provides several ways of declaring an abstract type and related operations, while hiding the type's representation.
If structure B depends upon structure A, and we wish to replace A by another structure A′, we could edit the program text and recompile the program. That is satisfactory if A is obsolete and can be discarded. But what if A and A′ are both useful, such as structures for floating point arithmetic in different precisions?
ml lets us declare B to take a structure as a parameter.
- Type
- Chapter
- Information
- ML for the Working Programmer , pp. 257 - 312Publisher: Cambridge University PressPrint publication year: 1996