<div dir="ltr"><p dir="ltr">Ali,</p>
<p dir="ltr">Nested lists with different nesting depths cannot be properly typed. You could probably get around this with a heterogenous collection (<a href="https://wiki.haskell.org/Heterogenous_collections">https://wiki.haskell.org/Heterogenous_collections</a>), but the mechanisms proposed there strike me as overkill for this problem. QuasiQuoters could definitely do it, by defining a new grammar construct. That would be quite advanced, and would teach you more about meta-programming than about trees, algorithms or functional programming.</p><p dir="ltr">Using Imants' suggestion, you would write:</p><p>n [l 'a', n [l 'b', l 'c', n []], l 'd']</p><p>This is just as much boiler plate as you had in your initial definition of tree, but it uses shorter identifiers.</p><p><br></p><p>Joel<br></p>
<br><div class="gmail_quote"><div dir="ltr">On Wed, 22 Jul 2015 19:27 Ali Baharev <<a href="mailto:ali.baharev@gmail.com" target="_blank">ali.baharev@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Dear Imants,<br>
<br>
Thanks. Unfortunately, I am not sure I get it. It seems to me that it<br>
generates a homogeneous list of either nodes with single leaver or<br>
just leaves. Or how would the<br>
<br>
['a', ['b', 'c', []], 'd']<br>
<br>
input look like, when using your proposed approach?<br>
<br>
Ali<br>
<br>
On Thu, Jul 23, 2015 at 1:10 AM, Imants Cekusins <<a href="mailto:imantc@gmail.com" target="_blank">imantc@gmail.com</a>> wrote:<br>
> how about this:<br>
><br>
><br>
> data Tree a = L a | N [Tree a] deriving Show<br>
><br>
><br>
> l::a -> Tree a<br>
> l = L<br>
><br>
> n::a -> Tree a<br>
> n x = N [L x]<br>
><br>
> m::(a->Tree a) ->[a]-> Tree a<br>
> m f list = N $ f <$> list<br>
><br>
><br>
> run it like this:<br>
> m l [2,3]<br>
> m n [2,3]<br>
><br>
> any good?<br>
> _______________________________________________<br>
> Beginners mailing list<br>
> <a href="mailto:Beginners@haskell.org" target="_blank">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" target="_blank">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>
</blockquote></div></div>