From: ross Date: Tue, 20 Jan 2004 13:57:25 +0000 (+0000) Subject: [project @ 2004-01-20 13:57:25 by ross] X-Git-Tag: nhc98-1-18-release~405 X-Git-Url: http://git.megacz.com/?a=commitdiff_plain;h=e32619e21061f6fa7107399f1f3540c8be542126;p=ghc-base.git [project @ 2004-01-20 13:57:25 by ross] use fields in Node --- diff --git a/Data/Tree.hs b/Data/Tree.hs index c68e66e..9f79763 100644 --- a/Data/Tree.hs +++ b/Data/Tree.hs @@ -25,7 +25,10 @@ import Prelude #endif -- | Multi-way trees, also known as /rose trees/. -data Tree a = Node a (Forest a) -- ^ a value and zero or more child trees. +data Tree a = Node { + rootLabel :: a, -- ^ label value + subForest :: Forest a -- ^ zero or more child trees + } #ifndef __HADDOCK__ deriving (Eq, Read, Show) #else /* __HADDOCK__ (which can't figure these out by itself) */ @@ -66,6 +69,6 @@ flatten t = squish t [] -- | Lists of nodes at each level of the tree. levels :: Tree a -> [[a]] -levels t = map (map root) $ takeWhile (not . null) $ iterate subforest [t] - where root (Node x _) = x - subforest f = [t | Node _ ts <- f, t <- ts] +levels t = map (map rootLabel) $ + takeWhile (not . null) $ + iterate (concatMap subForest) [t]