Re: [Haskell-cafe] Building a tree?
Example understood. Thanks. Is there a module for binary trees? Michael --- On Wed, 6/10/09, wren ng thornton w...@freegeek.org wrote: From: wren ng thornton w...@freegeek.org Subject: Re: [Haskell-cafe] Building a tree? To: haskell-cafe@haskell.org Date: Wednesday, June 10, 2009, 8:13 PM michael rice wrote: 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 ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Building a tree?
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 ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Building a tree?
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. Michael ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Building a tree?
On Wed, 10 Jun 2009, michael rice wrote: 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. unfoldTree (\n - (chr (n + ord 'a'), replicate n (n-1))) 3 Or did you expect a real world example? :-) ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Building a tree?
michael rice wrote: 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
Re: [Haskell-cafe] Building a tree?
michael rice wrote: 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. In as far as understanding it, it may be easier if you look at the generalized version of the anamorphism: newtype Fix f = Fix { unFix :: f (Fix f) } type Tree a = Fix (Node a) data Node a b = Node a [b] instance Functor (Node a) where fmap f (Node a bs) = Node a (map f bs) unfoldTree f = Fix . fmap (unfoldTree f) . f -- Live well, ~wren ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe