projects
/
ghc-base.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
2de78af
)
[project @ 2004-01-20 13:57:25 by ross]
author
ross
<unknown>
Tue, 20 Jan 2004 13:57:25 +0000
(13:57 +0000)
committer
ross
<unknown>
Tue, 20 Jan 2004 13:57:25 +0000
(13:57 +0000)
use fields in Node
Data/Tree.hs
patch
|
blob
|
history
diff --git
a/Data/Tree.hs
b/Data/Tree.hs
index
c68e66e
..
9f79763
100644
(file)
--- a/
Data/Tree.hs
+++ b/
Data/Tree.hs
@@
-25,7
+25,10
@@
import Prelude
#endif
-- | Multi-way trees, also known as /rose trees/.
#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) */
#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]]
-- | 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]