[Haskell-beginners] Parsing Terms in Brackets for Calculator
jeffbrown.the at gmail.com
Sat Feb 2 16:44:09 UTC 2019
You're in luck! Text.Megaparsec.Expr is designed to handle exactly this
problem. I put a tutorial of sorts in a fork of it on Github.
On Sat, Feb 2, 2019 at 3:03 AM Leonhard Applis <
Leonhard.Applis at protonmail.com> wrote:
> 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
> Beginners mailing list
> Beginners at haskell.org
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...
More information about the Beginners