[Haskell-beginners] Traversing generic trees
Ali Baharev
ali.baharev at gmail.com
Wed Jul 22 23:26:41 UTC 2015
Dear Imants,
Thanks. Unfortunately, I am not sure I get it. It seems to me that it
generates a homogeneous list of either nodes with single leaver or
just leaves. Or how would the
['a', ['b', 'c', []], 'd']
input look like, when using your proposed approach?
Ali
On Thu, Jul 23, 2015 at 1:10 AM, Imants Cekusins <imantc at gmail.com> wrote:
> how about this:
>
>
> data Tree a = L a | N [Tree a] deriving Show
>
>
> l::a -> Tree a
> l = L
>
> n::a -> Tree a
> n x = N [L x]
>
> m::(a->Tree a) ->[a]-> Tree a
> m f list = N $ f <$> list
>
>
> run it like this:
> m l [2,3]
> m n [2,3]
>
> any good?
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
More information about the Beginners
mailing list