<div dir="ltr"><div dir="ltr"><div dir="ltr">You're in luck! Text.Megaparsec.Expr[1] is designed to handle exactly this problem. I put a tutorial of sorts[2] in a fork of it on Github.<div><br></div><div>[1] <a href="https://www.stackage.org/haddock/nightly-2015-12-08/megaparsec-4.2.0/Text-Megaparsec-Expr.html">https://www.stackage.org/haddock/nightly-2015-12-08/megaparsec-4.2.0/Text-Megaparsec-Expr.html</a></div><div>[2] <a href="https://github.com/JeffreyBenjaminBrown/megaparsec/tree/master/Expr-studies">https://github.com/JeffreyBenjaminBrown/megaparsec/tree/master/Expr-studies</a></div></div></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sat, Feb 2, 2019 at 3:03 AM Leonhard Applis <<a href="mailto:Leonhard.Applis@protonmail.com">Leonhard.Applis@protonmail.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"><div>Hello, <br></div><div><br></div><div>I'm currently doing my first steps in Haskell with a calculator and I'm stuck at the parser. <br></div><div>I have a <i>data Term</i> which will build ... basically a tree of operations, and works fine.<br></div><div><br></div><div>I need help for the function <br></div><div>termify :: [Either Operator Term] -> Term<br></div><div><br></div><div>It takes operators (such as +,**) and terms and output a new, bigger term and is mostly trivial. <br></div><div>However, all attempts I've done for parsing brackets seem very ... crude and not like Haskell at all. <br></div><div><br></div><div>The very first pattern match should check for the innermost brackets, and return termify for everything in between.<br></div><div>I guess that I'm missing some really cool, haskelly solution here.<br></div><div> <br></div><div>Best Regards<br></div><div>Leonhard<br></div>_______________________________________________<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><br clear="all"><div><br></div>-- <br><div dir="ltr" class="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div>Jeff Brown | Jeffrey Benjamin Brown</div><div dir="ltr"><a href="https://msu.edu/~brown202/" style="font-size:12.8px" target="_blank">Website</a> | <a href="https://www.facebook.com/mejeff.younotjeff" style="font-size:12.8px" target="_blank">Facebook</a> | <a href="https://www.linkedin.com/in/jeffreybenjaminbrown" style="font-size:12.8px" target="_blank">LinkedIn</a><span style="font-size:12.8px">(spammy, so I often miss messages here) </span><span style="font-size:12.8px">|</span><span style="font-size:12.8px"> </span><a href="https://github.com/jeffreybenjaminbrown" style="font-size:12.8px" target="_blank">Github</a><span style="font-size:12.8px"> </span></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div>