The under-appreciated unfold
Authors:
Open Access
- 29 September 1998
- conference paper
- Published by Association for Computing Machinery (ACM)
- Vol. 34 (1) , 273-279
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.Keywords
This publication has 12 references indexed in Scilit:
- Functional PearlsJournal of Functional Programming, 2008
- Simple and efficient purely functional queues and dequesJournal of Functional Programming, 1995
- Functional Pearls A symmetric set of efficient list operationsJournal of Functional Programming, 1992
- Data structures and program transformationScience of Computer Programming, 1990
- Deforestation: transforming programs to eliminate treesTheoretical Computer Science, 1990
- Why Functional Programming MattersThe Computer Journal, 1989
- The promotion and accumulation strategies in transformational programmingACM Transactions on Programming Languages and Systems, 1984
- An efficient functional implementation of FIFO queuesInformation Processing Letters, 1982
- Real-time queue operations in pure LISPInformation Processing Letters, 1981
- Continuation-Based Program Transformation StrategiesJournal of the ACM, 1980