@gdmcbain

The Under-Appreciated Unfold

, and . Proceedings of the third ACM SIGPLAN international conference on Functional programming - ICFP '98, page 273--279. New York, ACM Press, (1998)
DOI: 10.1145/289423.289455

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.

Links and resources

Tags

community