
Example understood. Thanks.
Is there a module for binary trees?
Michael
--- On Wed, 6/10/09, wren ng thornton
Here's a function from Data.Tree:
unfoldTree :: (b -> (a, [b])) -> b -> Tree a Build a tree from a seed value
Could someone please give me a brief example of usage.
Data.Tree> let t = unfoldTree (\i -> (show i, [i`div`2..i-1])) Data.Tree> putStr . drawTree $ t 8 -- Live well, ~wren _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

michael rice wrote:
Example understood. Thanks.
Is there a module for binary trees?
Not that I know of off hand. Trees are one of those data structures with so many different variants that people end up rolling their own based on whatever they need at the time. Hence Data.Tree, Data.Sequence, Data.Set, Data.Map, Data.IntMap, Data.Trie,... -- Live well, ~wren

When folding is there a way to pick out the last point being processed? The first point can easily be picked out with (x:xs) but last xs crawls down the list. -- Regards, Casey

By swapping from foldl to foldr? Care to provide more detail? Casey Hawthorne wrote:
When folding is there a way to pick out the last point being processed?
The first point can easily be picked out with (x:xs) but last xs crawls down the list. -- Regards, Casey _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
-- Tony Morris http://tmorris.net/

Something like the belo 'foldL_last'? You could probably do it
cleaner, but I don't think there is a library function that would help
any more than foldl.
foldL_last :: (a -> b -> a) -> a -> [b] -> (Maybe b, a)
foldL_last f x xs = foldl (\(_,a) b -> (Just b, f a b)) (Nothing, x) xs
Tom
On Thu, Jun 11, 2009 at 6:47 PM, Casey Hawthorne
When folding is there a way to pick out the last point being processed?
The first point can easily be picked out with (x:xs) but last xs crawls down the list. -- Regards, Casey _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

Casey Hawthorne wrote:
When folding is there a way to pick out the last point being processed?
I came up with these: safeHead = foldr (const . Just) Nothing safeLast = foldr (flip mplus . Just) Nothing Claude -- http://claudiusmaximus.goto10.org
participants (6)
-
Casey Hawthorne
-
Claude Heiland-Allen
-
michael rice
-
Thomas DuBuisson
-
Tony Morris
-
wren ng thornton