[Haskell-cafe] lists of arbitrary depth
Shlomi Vaknin
shlomivaknin at gmail.com
Tue Jul 13 05:11:50 EDT 2010
Thank you all for replying!
I am really beginning my baby steps in this fascinating language, and was
just wondering if it was possible to naturally scan lists with arbitrary
lists (aka trees :) ).
I guess this forum specifically is too advancaed for me (yet!), so my next
questions will be posted on the beginners forum.
Thanks,
Vadali
On Tue, Jul 13, 2010 at 11:07 AM, Ivan Lazar Miljenovic <
ivan.miljenovic at gmail.com> wrote:
> vadali <shlomivaknin at gmail.com> writes:
>
> > hello,
> > iam really new to haskell,
> >
> > i want to define a function which takes as a parameter a list which can
> > contain other lists, eg. [1,[2,3],[4,[5,6]]]
> >
> > how would i define a function that can iterate through the items so (in
> this
> > example)
> > iter1 = 1
> > iter2 = [2,3]
> > iter3 = [4,[5,6]]
> >
> > ?
> >
> > ( can i do that without using the Tree data type? )
>
> Well, that's what a tree is, so why not use a tree?
>
> Your only other option is to define your own tree-like structure:
>
> data MyTree a = Value a | SubTree [MyTree a]
>
> >
> > THANKS!
>
> YOUR WELCOME! :p
>
> --
> Ivan Lazar Miljenovic
> Ivan.Miljenovic at gmail.com
> IvanMiljenovic.wordpress.com
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20100713/61abae8e/attachment.html
More information about the Haskell-Cafe
mailing list