I have the DataType
data Rose a = Leaf a | Node [Rose a]
an example would be:
fmfp = Node [Node [Leaf "F"], Node [], Node [Leaf "F", Leaf "P"], Leaf "M"]
which graphically looks like this:
I have learned how to (mechanically) write fold functions for different data types, and so I came up with this fold function:
foldRose :: (a -> r) -> ([r] -> r) -> Rose a -> r
foldRose fl fn Leaf a = fl a
foldRose fl fn Node a = fn (map (foldRose fl fn)) a
The thing is, I don't really understand WHAT it does. For example, if I had
foldRose id concat fmfp
what would it do exactly? Would it be
foldRose id concat fmfp = concat [concat [id "F"], concat [],
concat [id "F", id "P"], id "M"]
How do you wrap your mind around those kinds of functions? What do they intuitively mean? Also, how do I write a mapRose function, what would I have to think befre starting, what would it be supposed to do?