Send Beginners mailing list submissions to
        beginners@haskell.org

To subscribe or unsubscribe via the World Wide Web, visit
        http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
        beginners-requ...@haskell.org

You can reach the person managing the list at
        beginners-ow...@haskell.org

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."


Today's Topics:

   1. Re:  Parsing Terms in Brackets for Calculator (Jeffrey Brown)
   2. Re:  Using a monad function inside the monad transfomer
      variant (Moritz Tacke)


----------------------------------------------------------------------

Message: 1
Date: Sat, 2 Feb 2019 11:44:09 -0500
From: Jeffrey Brown <jeffbrown....@gmail.com>
To: Leonhard Applis <leonhard.app...@protonmail.com>,  The
        Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <beginners@haskell.org>
Subject: Re: [Haskell-beginners] Parsing Terms in Brackets for
        Calculator
Message-ID:
        <CAEc4Ma1oiJiPPA7J5iSpE7HvZtW7teTMyK=-8glaczcp2+v...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

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.app...@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@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-0001.html>

------------------------------

Message: 2
Date: Sat, 2 Feb 2019 19:50:22 +0100
From: Moritz Tacke <moritz.ta...@gmail.com>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <beginners@haskell.org>
Subject: Re: [Haskell-beginners] Using a monad function inside the
        monad transfomer variant
Message-ID:
        <canztob2dc4md5l8ab2bv+gpqfhpf-rf3dswtxncmmxxk1fx...@mail.gmail.com>
Content-Type: text/plain; charset="UTF-8"

Ok, thank you, I'll try!
Just to understand this: Is this due to a specific reason? Couldn't
the compiler infer from a definition of a RVar that the same function
can also be used in the RVarT situation? It would (somehow) look
cleaner and I do not see any differences in the semantics

On Fri, Feb 1, 2019 at 6:57 PM Seph Shewell Brockway <s...@codex.scot> wrote:
>
> On Fri, Feb 01, 2019 at 03:14:32PM +0100, Moritz Tacke wrote:
> > Hi,
> >
> > I still want to use the functions that return RVars, so eg.
> >
> > rvarDouble :: RVar Double
> >
> > and then the definition of the transformer function would be:
> >
> > someFunction a b =
> >     do ...
> >          the_double <- rvarDouble
> >          ....
> >
> > This does not compile, complaining that;
> >
> >    • Couldn't match type ‘Data.Functor.Identity.Identity’ with ‘ST s’
> >       Expected type: RVarT (ST s) Double
> >         Actual type: RVar Double
> >
> > How can I re-user the RVar function in the RVarT monad transformer?
>
> Your declaration of rvarDouble needs to be polymorphic in the monad:
>
>    rvarDouble :: Monad m => RVarT m Double
>
> The crucial observation is that RVar is actually a type synonym for
> RVarT Identity, so the function can still be made to return a plain
> RVar Double, but it can also return an RVarT (ST s) Double, satisfying
> the type-checker in the example that you gave.
>
> --
> Seph Shewell Brockway, BSc MSc (Glas.)
> _______________________________________________
> Beginners mailing list
> Beginners@haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners


------------------------------

Subject: Digest Footer

_______________________________________________
Beginners mailing list
Beginners@haskell.org
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners


------------------------------

End of Beginners Digest, Vol 128, Issue 2
*****************************************

Reply via email to