[project @ 1996-07-25 21:02:03 by partain]
[nofib.git] / spectral / minimax / Tree.hs
1 module Tree where
2
3 data Tree a = Branch a [Tree a] deriving Show{-was:Text-}
4
5 repTree :: (a->[a]) -> (a->[a])-> a -> (Tree a)
6 repTree f g a = Branch a (map (repTree g f) (f a))
7
8
9 mapTree :: (a -> b) -> (Tree a) -> (Tree b)
10 mapTree f (Branch a l) = Branch (f a) (map (mapTree f) l)
11
12 prune :: Int -> (Tree a) -> (Tree a)
13 prune 0 (Branch a l) = Branch a []
14 --should be:prune (n+1) (Branch a l) = Branch a (map (prune n) l)
15 prune n (Branch a l) | n < 0 = error "Tree.prune: < 0"
16 | otherwise = Branch a (map (prune (n-1)) l)
17