Unfolding trees breadth-first in Haskell

To visit a tree or graph in breadth-first order, there are two main implementation approaches: queue-based or level-based. Our goal here is to develop a level-based approach where the levels of the breadth-first walk are constructed compositionally and dynamically . Compositionality means that for every node, its descendants—the other nodes reachable from it—are defined by composing the…