Abstract:
Folds are appreciated by functional programmers. Their dual, unfolds, are not new, but they are not nearly as well appreciated. We believe they deserve better. To illustrate, we present (indeed, we calculate) a number of algorithms for computing the breadth-first traversal of a tree. We specify breadth-first traversal in terms of level-order traversal, which we characterize first as a fold. The presentation as a fold is simple, but it is inefficient, and removing the inefficiency makes it no longer a fold. We calculate a characterization as an unfold from the characterization as a fold; this unfold is equally clear, but more efficient. We also calculate a characterization of breadth-first traversal directly as an unfold; this turns out to be the `standard' queue-based algorithm.
Citations
|
1122
|
Introduction to Functional Programming
– Bird, Wadler
- 1988
|
|
404
|
The Science of Programming
– Gries
- 1981
|
|
341
|
Deforestation: transforming programs to eliminate trees
– Wadler
- 1990
|
|
250
|
Functional programming with bananas, lenses, envelopes and barbed wire
– Meijer, Fokkinga, et al.
- 1991
|
|
244
|
Why functional programming matters
– Hughes
- 1989
|
|
172
|
Introduction to Functional Programming using Haskell
– Bird
- 1998
|
|
100
|
Data structures and program transformation
– Malcolm
- 1990
|
|
80
|
Addendum: The promotion and accumulation strategies in transformational programming
– Bird
- 1985
|
|
78
|
Type Theory and Functional Programming
– Thompson
- 1991
|
|
45
|
Revisiting catamorphisms over datatypes with embedded functions (or, programs from outer space
– Fegaras, Sheard
- 1996
|
|
44
|
A typed lambda calculus with categorical type constructors
– Hagino
- 1987
|
|
44
|
Continuation-based program transformation strategies
– Wand
- 1980
|
|
24
|
Simple and efficient purely functional queues and deques
– Okasaki
- 1995
|
|
22
|
Algebras for Tree Algorithms
– Gibbons
- 1991
|
|
14
|
An efficient functional implementation of FIFO queues
– BURTON
- 1982
|
|
11
|
A symmetric set of efficient list operations
– Hoogerwoord
- 1992
|
|
7
|
First steps towards the theory of rose trees
– Meertens
- 1988
|
|
6
|
Real-time queue operations in pure Lisp
– Hood, Melville
- 1981
|
|
5
|
Deriving tidy drawings of trees
– Gibbons
- 1996
|
|
4
|
Masato Takeichi. Deriving structural hylomorphisms from recursive definitions
– Hu, Iwasaki
- 1996
|
|
4
|
Linear-time breadth-first tree algorithms: an exercise in the arithmetic of folds and zips
– Jones, Gibbons
- 1993
|
|
2
|
Addendum to "The promotion and accumulation strategies in transformational programming
– Bird
- 1985
|
|
2
|
The Haskell 1.4 report. http://www.haskell.org/report
– Peterson, Hammond, et al.
- 1997
|