Plan 9 from Bell Labs’s /usr/web/sources/contrib/fernan/nhc98/tests/nofib/spectral/minimax/Tree.hs

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.


module Tree where

data Tree a = Branch a [Tree a] deriving Show{-was:Text-}

repTree :: (a->[a]) -> (a->[a])-> a -> (Tree a)
repTree f g a = Branch a (map (repTree g f) (f a))


mapTree :: (a -> b) -> (Tree a) -> (Tree b)
mapTree f (Branch a l) = Branch (f a) (map (mapTree f) l)

prune :: Int -> (Tree a) -> (Tree a)
prune 0 (Branch a l) = Branch a []
--should be:prune (n+1) (Branch a l) = Branch a (map (prune n) l)
prune n (Branch a l) | n < 0     = error "Tree.prune: < 0"
		     | otherwise = Branch a (map (prune (n-1)) l)


Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to webmaster@9p.io.