1 implementation module StdRoseTree
3 /** This module defines rose trees.
7 root :: !(RoseTree a) -> a
10 children :: !(RoseTree a) -> [RoseTree a]
11 children (Node _ ts) = ts
13 depth :: !(RoseTree a) -> Int
15 depth (Node _ xs) = 1 + maxList (map depth xs)
17 prunetree :: !PruneDepth !(RoseTree a) -> RoseTree a
18 prunetree d (Node x ts)
20 | otherwise = Node x (map (prunetree (d-1)) ts)
22 bonsai :: !(RoseTree a) -> RoseTree a | Eq a
23 bonsai t = bonsai` [] t
25 bonsai` :: ![a] !(RoseTree a) -> RoseTree a | Eq a
26 bonsai` path (Node v ts) = Node v (filter (\t -> not (isMember (root t) [v:path]))
27 (map (bonsai` [v:path]) ts)
30 iteratetree :: !(Children a) a -> RoseTree a
31 iteratetree f s = Node s (map (iteratetree f) (f s))
33 maptree :: (a -> b) !(RoseTree a) -> RoseTree b
34 maptree f (Node x ts) = Node (f x) (map (maptree f) ts)
36 paths :: !(RoseTree a) -> [[a]]
37 paths (Node x []) = [[x]]
38 paths (Node x ts) = [[x:path] \\ t <- ts, path <- paths t]