I'm working with a version of a Tree of the type:
Tree = Empty | Leaf Event | Split String [(String, Tree)]
My aim is to get a function that returns a list of pairs [(Event,[Int])]
with [Int]
being the coordinates (the path taken in the tree to reach it) of each Event, i.e if the tree was:
Split str [(str2, Leaf event), (str3, Empty)]
Then I would want it to return [event,[0]]
. I want to ignore any empty ends to the tree.
so my function looks like
coords :: Tree -> [(Event,[Int])]
coords Empty = []
coords (Leaf event) = [event, []]
Then for Split it needs to recursively apply the function on each subtree. I thought of doing:
coords Split str xs = zip (coords trees) [1..] where
trees = [snd(str,tree) | (str,tree) <-xs]
But this would give me nested lists of arbitrary length, among a couple of other problems. Any ideas?