From e32619e21061f6fa7107399f1f3540c8be542126 Mon Sep 17 00:00:00 2001 From: ross Date: Tue, 20 Jan 2004 13:57:25 +0000 Subject: [PATCH] [project @ 2004-01-20 13:57:25 by ross] use fields in Node --- Data/Tree.hs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) 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] -- 1.7.10.4