If you add an instance of IsString to handle leaf construction you can get it down to<div><br></div><div> "Fruits" +> do</div><div> "Apple"</div><div> "Mango"</div><div> "Arbitrary" +> do</div>
<div> "1"</div><div> "..."</div><div><br></div><div>But I also don't see the point of doing this in a monad.</div><div><br></div><div>-Edward<br><br><div class="gmail_quote">On Tue, Mar 22, 2011 at 1:15 PM, Yves Parès <span dir="ltr"><<a href="mailto:limestrael@gmail.com">limestrael@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">You could turn 'insertSubTree' into and operator, and shorten "insertLeaf"<br><br style="font-family:courier new,monospace">
<span style="font-family:courier new,monospace">createTree = do</span><br style="font-family:courier new,monospace">
<span style="font-family:courier new,monospace"> "Fruits" +> do</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace"> leaf "Apple"</span><br style="font-family:courier new,monospace">
<span style="font-family:courier new,monospace"> leaf "Mango</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace"> "Arbitrary" +> do<br>
leaf "1"<br> -- and so on...<br><br><span style="font-family:arial,helvetica,sans-serif">It's a little bit more concise.</span><br></span>But I fail to see the use of TreeContext being an instance of Monad.<br>
<br><div class="gmail_quote"><div><div></div><div class="h5">2011/3/22 C K Kashyap <span dir="ltr"><<a href="mailto:ckkashyap@gmail.com" target="_blank">ckkashyap@gmail.com</a>></span><br></div></div><blockquote class="gmail_quote" style="border-left:1px solid rgb(204, 204, 204);margin:0pt 0pt 0pt 0.8ex;padding-left:1ex">
<div><div></div><div class="h5">
Hi,<div>With my "edsl", one can describe a tree like this -</div><div><br></div><div>import TreeEdsl</div><div>import Data.Tree</div><div><br></div><div>createTree :: TreeContext String ()</div><div>createTree = do</div>
<div><span style="white-space:pre-wrap">        </span>insertSubTree "Fruits" $ do</div><div><span style="white-space:pre-wrap">                </span>insertLeaf "Apple"</div><div><span style="white-space:pre-wrap">                </span>insertLeaf "Mango"</div>
<div><span style="white-space:pre-wrap">        </span>insertSubTree "Arbitrary" $ do</div><div><span style="white-space:pre-wrap">                </span>insertSubTree "Numbers" $ do</div>
<div><span style="white-space:pre-wrap">                        </span>insertLeaf "1"</div><div><span style="white-space:pre-wrap">                        </span>insertLeaf "2"</div><div><span style="white-space:pre-wrap">                        </span>insertLeaf "3"</div>
<div><span style="white-space:pre-wrap">                </span>insertSubTree "Letters" $ do</div><div><span style="white-space:pre-wrap">                        </span>insertLeaf "A"</div><div><span style="white-space:pre-wrap">                        </span>insertLeaf "B"</div>
<div><span style="white-space:pre-wrap">                        </span>insertLeaf "C"</div><div><span style="white-space:pre-wrap">        </span>return ()</div><div><span style="white-space:pre-wrap">        </span></div>
<div>main = do</div><div><span style="white-space:pre-wrap">        </span>tree <- process "root" createTree</div><div><span style="white-space:pre-wrap">        </span>putStrLn (drawTree (fmap show tree))</div>
<div><span style="white-space:pre-wrap">        </span>return ()</div><div><br></div><div><br></div><div>and get a tree like this - </div><div><div><br></div><div>"root"</div><div>
|</div><div>+- "Arbitrary"</div><div>| |</div><div>| +- "Letters"</div><div>| | |</div><div>| | +- "C"</div><div>| | |</div><div>| | +- "B"</div><div>| | |</div><div>| | `- "A"</div>
<div>| |</div><div>| `- "Numbers"</div><div>| |</div><div>| +- "3"</div><div>| |</div><div>| +- "2"</div><div>| |</div><div>| `- "1"</div><div>|</div><div>
`- "Fruits"</div><div> |</div><div> +- "Mango"</div><div> |</div><div> `- "Apple"</div></div><div><br></div><div> </div><div><div>My code is here </div><div><a href="https://github.com/ckkashyap/LearningPrograms/blob/master/Haskell/edsl/TreeEdsl.hs" target="_blank">https://github.com/ckkashyap/LearningPrograms/blob/master/Haskell/edsl/TreeEdsl.hs</a></div>
</div><div><br></div><div>I'd appreciate your feedback on this. Does this qualify to be a edsl?</div><div><br></div><div>Regards,</div><div>Kashyap</div>
<br></div></div>_______________________________________________<br>
Haskell-Cafe mailing list<br>
<a href="mailto:Haskell-Cafe@haskell.org" target="_blank">Haskell-Cafe@haskell.org</a><br>
<a href="http://www.haskell.org/mailman/listinfo/haskell-cafe" target="_blank">http://www.haskell.org/mailman/listinfo/haskell-cafe</a><br>
<br></blockquote></div><br>
<br>_______________________________________________<br>
Haskell-Cafe mailing list<br>
<a href="mailto:Haskell-Cafe@haskell.org">Haskell-Cafe@haskell.org</a><br>
<a href="http://www.haskell.org/mailman/listinfo/haskell-cafe" target="_blank">http://www.haskell.org/mailman/listinfo/haskell-cafe</a><br>
<br></blockquote></div><br></div>