I wonder whether it would be possible to simplify this function by splitting it into two parts. One, tentatively called `flattenBFS` would produce a list of trees that result from traversing a tree in a BFS order. Another one, called `List.map` would just apply `f` to the result of flatten. The joy of functional programming :)