<div dir="ltr">You should not try and use the built-in lists or tuples to represent a tree data structure. That's not what they're good at. You probably could make tuples work and write functions using GHC.Generics to work with it as a tree data structure, but it definitely won't be easy or elegant. If you want a more economic syntax for expressing the tree you can provide shorter names for Leaf and Node (one char isn't too bad), or else you're stuck with using a parser. You may not have to write a parser though, perhaps JSON or YAML would work fine for this. If it needs to go in the source file, there's always TemplateHaskell and QuasiQuotes.</div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Jul 23, 2015 at 9:48 AM, Ali Baharev <span dir="ltr"><<a href="mailto:ali.baharev@gmail.com" target="_blank">ali.baharev@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Dear All,<br>
<br>
I used to work at the University. Whenever a student asked me a<br>
question, I first focused on the question and tried to answer it.<br>
Sometimes the question was tough, maybe because there wasn't any easy<br>
solution to the problem. In those situations I used to say to my<br>
students: “Problem well spotted, unfortunately I cannot give you an<br>
answer / there is no easy solution to this problem.” However, I have<br>
never started questioning the questions of my students, especially<br>
when I could not give them an answer.<br>
<br>
According to the Wiki on <a href="mailto:beginners@haskell.org">beginners@haskell.org</a>: "Here, there is no<br>
such thing as a 'stupid question.'" If you start questioning my<br>
question, then I really do not know where to go...<br>
<br>
You might as well say: The whole question is pointless, just use<br>
Data.Tree and be done with it!<br>
<br>
It is really not part of the original question, and I sooo not want to<br>
get into a discussion over this: It is important to have language<br>
support for helping humans to input data, without a full-blown parser.<br>
Examples would be user-defined implicit type conversions and<br>
user-defined literals in other statically typed languages.<br>
<br>
OK, let's get back to the original question.<br>
<br>
Apparently, there is no easy way to solve it with nested lists.<br>
However, no one has touched the nested tuples so far. How can I write<br>
a toString function that works similarly to mine but destructures<br>
arbitrarily nested tuples?<br>
<br>
Thanks,<br>
<br>
Ali<br>
<div class="HOEnZb"><div class="h5"><br>
On Thu, Jul 23, 2015 at 9:41 AM, Imants Cekusins <<a href="mailto:imantc@gmail.com">imantc@gmail.com</a>> wrote:<br>
> .. on the other hand, if facing this problem:<br>
> - import large trees from concise human-readable representation as string<br>
><br>
> , it is probably possible to write a parser which does just that.<br>
><br>
> After all json parser works somehow ;)<br>
><br>
> Just saying that you could do this in Haskell, given enough interest.<br>
> _______________________________________________<br>
> Beginners mailing list<br>
> <a href="mailto:Beginners@haskell.org">Beginners@haskell.org</a><br>
> <a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners" rel="noreferrer" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners</a><br>
_______________________________________________<br>
Beginners mailing list<br>
<a href="mailto:Beginners@haskell.org">Beginners@haskell.org</a><br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners" rel="noreferrer" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners</a><br>
</div></div></blockquote></div><br></div>