The under-appreciated unfold

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, ve present (indeed, we calculate) a number of algorithms for computing the breadth-first traversal of a tree. We specify brea...

Disgrifiad llawn

Manylion Llyfryddiaeth
Prif Awduron: Gibbons, J, Jones, G
Fformat: Conference item
Cyhoeddwyd: 1999
Disgrifiad
Crynodeb: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, ve 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. © 1998 ACM.