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

Reply via email to