2 ms·
Maps and folds, at the very least, generalize to trees fairly naturally. They also behave essentially the same way as for lists. If you want more versatile fun
by tikhonj 14y ago
Maps and folds, at the very least, generalize to trees fairly naturally. They also behave essentially the same way as for lists.
If you want more versatile functions, you could look at the famous "Bananas, Envelopes, Lenses and Barbed Wire" paper which introduces a bunch of recursion schemes that apply to trees as well as lists and other structures. These have Greek names you might have heard like "catamorphism" (a generalized fold).
Even if you don't end up using the functions, it's a good read. Might be a bit dense though, but it's not that bad or terribly heavy on math.