[project @ 2004-01-20 13:57:25 by ross]
authorross <unknown>
Tue, 20 Jan 2004 13:57:25 +0000 (13:57 +0000)
committerross <unknown>
Tue, 20 Jan 2004 13:57:25 +0000 (13:57 +0000)
use fields in Node

Data/Tree.hs

index c68e66e..9f79763 100644 (file)
@@ -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]