<div dir="ltr">Thank you Bob,<div>your example clarified how actually using such data type would appear in haskell. I naively thought it would be as simple as defining a regular list, but i see it is slightly more strict than that. I appreciate your help!</div>
<div><br></div><div>Vadali<br><div><br><div class="gmail_quote">On Tue, Jul 13, 2010 at 11:18 AM, Thomas Davie <span dir="ltr"><<a href="mailto:tom.davie@gmail.com">tom.davie@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div class="im"><br>
On 13 Jul 2010, at 10:11, Shlomi Vaknin wrote:<br>
<br>
> Thank you all for replying!<br>
><br>
> 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 :) ).<br>
<br>
</div>Trees aren't lists, Trees are trees... Here's how you create one*<br>
<br>
data Tree a = Leaf<br>
| Branch a [Tree a]<br>
<br>
This roughly says, a tree can be made up of two possible things... First, it could be a leaf, and secondly, it could be a branch with an element at it, and a list of subtrees.<br>
<br>
Some example trees using this data type:<br>
<br>
1) Leaf<br>
2) Branch 5 []<br>
3) Branch 5 [Leaf]<br>
4) Branch 5 [Branch 10 [], Branch 20 [], Leaf, Branch 50 [Branch 10 [], Leaf]]<br>
<br>
When you have really strong typing, you also have very well specified types. You don't just use a list as if it were a tree, you declare what a tree is.<br>
<br>
Bob<br>
<br>
* In this case an arbitrarily branching tree, we could ofc declare different forms of tree here.</blockquote></div><br></div></div></div>