
19 Sep
2005
19 Sep
'05
9:05 a.m.
On Mon, Sep 19, 2005 at 12:52:47PM +0200, Rene de Visser wrote:
-- This function can effectively only be used bottom up, because the only input -- parameter to func comes from the call "(map (treeFold func))", i.e. the rest of -- the tree. We can only tell when are are at a leaf ( [b] is empty ). -- Add in the other tree fold here! treeFold :: (a -> [b] -> b) -> Tree a -> b treeFold func (Node header list) = func header (map (treeFold func) list)
You can define paths with treeFold in this way: paths t = treeFold (\a fs p -> let p' = p ++ [a] in if null fs then [p'] else concatMap ($ p') fs) t [] So treeFold can be used top-down :-) Best regards Tomasz