I have a tree:
a :: Tree Double
a =
Node 1
[Node 20
[Node 300
[Node 400 [],
Node 500 []],
Node 310 []],
Node 30 [],
Node 40 []]
I want to apply it an scan
operation similar to lists - except that, instead of returning a list, it should return a tree with the travelled paths. For example:
scan (+) 0 a
Should reduce to:
Node 1
[Node 21
[Node 321
[Node 721 [],
Node 821 []],
Node 331 []],
Node 31 [],
Node 41 []]
Which is accumulated the sums through the tree. Is there a standard function for this?
If you want to pass an accumulator, then the definition is
This version is also quite more efficient, compare this and this.