Book contents
- Frontmatter
- Contents
- Preface
- 1 Introduction
- 2 Persistence
- 3 Some Familiar Data Structures in a Functional Setting
- 4 Lazy Evaluation
- 5 Fundamentals of Amortization
- 6 Amortization and Persistence via Lazy Evaluation
- 7 Eliminating Amortization
- 8 Lazy Rebuilding
- 9 Numerical Representations
- 10 Data-Structural Bootstrapping
- 11 Implicit Recursive Slowdown
- A Haskell Source Code
- Bibliography
- Index
2 - Persistence
Published online by Cambridge University Press: 17 September 2009
- Frontmatter
- Contents
- Preface
- 1 Introduction
- 2 Persistence
- 3 Some Familiar Data Structures in a Functional Setting
- 4 Lazy Evaluation
- 5 Fundamentals of Amortization
- 6 Amortization and Persistence via Lazy Evaluation
- 7 Eliminating Amortization
- 8 Lazy Rebuilding
- 9 Numerical Representations
- 10 Data-Structural Bootstrapping
- 11 Implicit Recursive Slowdown
- A Haskell Source Code
- Bibliography
- Index
Summary
A distinctive property of functional data structures is that they are always persistent―updating a functional data structure does not destroy the existing version, but rather creates a new version that coexists with the old one. Persistence is achieved by copying the affected nodes of a data structure and making all changes in the copy rather than in the original. Because nodes are never modified directly, all nodes that are unaffected by an update can be shared between the old and new versions of the data structure without worrying that a change in one version will inadvertently be visible to the other.
In this chapter, we examine the details of copying and sharing for two simple data structures: lists and binary search trees.
Lists
We begin with simple linked lists, which are common in imperative programming and ubiquitous in functional programming. The core functions supported by lists are essentially those of the stack abstraction, which is described as a Standard ML signature in Figure 2.1. Lists and stacks can be implemented trivially using either the built-in type of lists (Figure 2.2) or a custom datatype (Figure 2.3).
Remark The signature in Figure 2.1 uses list nomenclature (cons, head, tail) rather than stack nomenclature (push, top, pop), because we regard stacks as an instance of the general class of sequences.
- Type
- Chapter
- Information
- Purely Functional Data Structures , pp. 7 - 16Publisher: Cambridge University PressPrint publication year: 1998