[Haskell-beginners] Parsing Terms in Brackets for Calculator

Jeffrey Brown jeffbrown.the at gmail.com
Sat Feb 2 16:44:09 UTC 2019


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.

[1]
https://www.stackage.org/haddock/nightly-2015-12-08/megaparsec-4.2.0/Text-Megaparsec-Expr.html
[2]
https://github.com/JeffreyBenjaminBrown/megaparsec/tree/master/Expr-studies

On Sat, Feb 2, 2019 at 3:03 AM Leonhard Applis <
Leonhard.Applis at protonmail.com> wrote:

> Hello,
>
> I'm currently doing my first steps in Haskell with a calculator and I'm
> stuck at the parser.
> I have a *data Term* which will build ... basically a tree of operations,
> and works fine.
>
> I need help for the function
> termify :: [Either Operator Term] -> Term
>
> It takes operators (such as +,**) and terms and output a new, bigger term
> and is mostly trivial.
> However, all attempts I've done for parsing brackets seem very ... crude
> and not like Haskell at all.
>
> The very first pattern match should check for the innermost brackets, and
> return termify for everything in between.
> I guess that I'm missing some really cool, haskelly solution here.
>
> Best Regards
> Leonhard
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>


-- 
Jeff Brown | Jeffrey Benjamin Brown
Website <https://msu.edu/~brown202/>   |   Facebook
<https://www.facebook.com/mejeff.younotjeff>   |   LinkedIn
<https://www.linkedin.com/in/jeffreybenjaminbrown>(spammy, so I often miss
messages here)   |   Github <https://github.com/jeffreybenjaminbrown>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/beginners/attachments/20190202/479b55e0/attachment.html>


More information about the Beginners mailing list