The 13-line example in Text.Megaparsec.Expr

At the bottom of the Hackage documentation for Text.Megaparsec.Expr [1] is a 13-line demonstration program. It includes no import statements. I added the ones I could deduce, which produced this: import Text.Megaparsec import Text.Megaparsec.Expr import Text.Megaparsec.Lexer (symbol,integer) parens = between (symbol "(") (symbol ")") expr = makeExprParser term table <?> "expression" term = parens expr <|> integer <?> "term" table = [ [ prefix "-" negate , prefix "+" id ] , [ postfix "++" (+1) ] , [ binary "*" (*) , binary "/" div ] , [ binary "+" (+) , binary "-" (-) ] ] binary name f = InfixL (reservedOp name >> return f) prefix name f = Prefix (reservedOp name >> return f) postfix name f = Postfix (reservedOp name >> return f) That still won't compile, because GHC does not know what reservedOp means. Does reservedOp refer to something that no longer exists, or have I just not found it? [1] https://hackage.haskell.org/package/megaparsec-4.4.0/docs/Text-Megaparsec-Ex... -- Jeffrey Benjamin Brown

https://hackage.haskell.org/package/parsec-3.1.9/docs/Text-Parsec-Token.html...
?
--Will
On Fri, Feb 26, 2016 at 10:08 PM, Jeffrey Brown
That still won't compile, because GHC does not know what reservedOp means. Does reservedOp refer to something that no longer exists, or have I just not found it?

Thanks, Will. I had tried that, and got a lot of errors like this:
example.hs:20:26:
Couldn't match type ‘Char’ with ‘()’
Expected type: [()]
Actual type: [Char]
In the first argument of ‘symbol’, namely ‘"("’
In the first argument of ‘between’, namely ‘(symbol "(")’
In the expression: between (symbol "(") (symbol ")")
On Fri, Feb 26, 2016 at 8:20 PM, William Yager
https://hackage.haskell.org/package/parsec-3.1.9/docs/Text-Parsec-Token.html... ?
--Will
On Fri, Feb 26, 2016 at 10:08 PM, Jeffrey Brown
wrote: That still won't compile, because GHC does not know what reservedOp means. Does reservedOp refer to something that no longer exists, or have I just not found it?
-- Jeffrey Benjamin Brown

In my previous email I perhaps should have also reported a second type of
error:
example.hs:26:21:
Couldn't match expected type ‘Text.Parsec.Token.GenTokenParser
s0 u0 m0’
with actual type ‘[Char]’
In the first argument of ‘prefix’, namely ‘"-"’
In the expression: prefix "-" negate
In the expression: [prefix "-" negate, prefix "+" id]
On Fri, Feb 26, 2016 at 10:05 PM, Jeffrey Brown
Thanks, Will. I had tried that, and got a lot of errors like this:
example.hs:20:26: Couldn't match type ‘Char’ with ‘()’ Expected type: [()] Actual type: [Char] In the first argument of ‘symbol’, namely ‘"("’ In the first argument of ‘between’, namely ‘(symbol "(")’ In the expression: between (symbol "(") (symbol ")")
On Fri, Feb 26, 2016 at 8:20 PM, William Yager
wrote: https://hackage.haskell.org/package/parsec-3.1.9/docs/Text-Parsec-Token.html... ?
--Will
On Fri, Feb 26, 2016 at 10:08 PM, Jeffrey Brown
wrote: That still won't compile, because GHC does not know what reservedOp means. Does reservedOp refer to something that no longer exists, or have I just not found it?
-- Jeffrey Benjamin Brown
-- Jeffrey Benjamin Brown

Hi.
On 27 February 2016 at 04:20, William Yager
https://hackage.haskell.org/package/parsec-3.1.9/docs/Text-Parsec-Token.html... ?
If I understand it correctly, Jeffrey is asking about using Megaparsec, and this link is to the parsec combinator with the same name. I am very surprised to find out that Megaparsec does not provide[*] the same combinator. Especially since they keep the same example! [*] At least it is not listed here: http://hackage.haskell.org/package/megaparsec-4.4.0/docs/doc-index-All.html -- Özgür Akgün

Megaparsec does away with Parsec's LanguageDef machinery (which
provides reservedOp). This is a double edge sword - as Megaparsec's
author notes Parsec lexers (i.e LanguageDef based lexers) are
inflexible especially if you need whitespace sensitive parsing; but
they are very handy for the simple case of whitespace insensitive
parsing.
For the expression parser, Megaparsec's documentation is wrong[*] and
probably it should use symbol rather than reservedOp. Note that symbol
is slightly different in Megaparsec as it's a plain combinator (rather
than one instantiated from a first class module as in Parsec) so it
takes two args rather than one.
[*] Well, likely wrong - I haven't got round to using Megaparsec yet.
On 27 February 2016 at 17:04, Özgür Akgün
Hi.
On 27 February 2016 at 04:20, William Yager
wrote: https://hackage.haskell.org/package/parsec-3.1.9/docs/Text-Parsec-Token.html... ?
If I understand it correctly, Jeffrey is asking about using Megaparsec, and this link is to the parsec combinator with the same name.
I am very surprised to find out that Megaparsec does not provide[*] the same combinator. Especially since they keep the same example!
[*] At least it is not listed here: http://hackage.haskell.org/package/megaparsec-4.4.0/docs/doc-index-All.html
-- Özgür Akgün
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe

On 29 February 2016 at 08:22, Stephen Tetley
For the expression parser, Megaparsec's documentation is wrong[*] and probably it should use symbol rather than reservedOp. Note that symbol is slightly different in Megaparsec as it's a plain combinator (rather than one instantiated from a first class module as in Parsec) so it takes two args rather than one.
[*] Well, likely wrong - I haven't got round to using Megaparsec yet.
You are right: https://github.com/mrkkrp/megaparsec/commit/750adb7c70392c3195eda12d816f4a1a... -- Özgür Akgün

I'm trying this again! The comment for Megaparsec.makeExprParser refers to
"parens". When I grep for "parens" in Megaparsec I get only two occurences,
both of them in comments:
./Lexer.hs:-- > parens = between (symbol "(") (symbol ")")
./Expr.hs:-- > term = parens expr <|> integer > "term"
If I try defining parens as in the comment from Lexer.hs, I get these
errors:
<interactive>:37:33:
Couldn't match type ‘Char’ with ‘()’
Expected type: [()]
Actual type: [Char]
In the first argument of ‘symbol’, namely ‘"("’
In the first argument of ‘between’, namely ‘(symbol "(")’
In the expression: between (symbol "(") (symbol ")")
<interactive>:37:46:
Couldn't match type ‘Char’ with ‘()’
Expected type: [()]
Actual type: [Char]
In the first argument of ‘symbol’, namely ‘")"’
In the second argument of ‘between’, namely ‘(symbol ")")’
In the expression: between (symbol "(") (symbol ")")
[1]
https://hackage.haskell.org/package/megaparsec-5.0.1/docs/Text-Megaparsec-Ex...
On Mon, Feb 29, 2016 at 2:05 AM, Özgür Akgün
On 29 February 2016 at 08:22, Stephen Tetley
wrote: For the expression parser, Megaparsec's documentation is wrong[*] and probably it should use symbol rather than reservedOp. Note that symbol is slightly different in Megaparsec as it's a plain combinator (rather than one instantiated from a first class module as in Parsec) so it takes two args rather than one.
[*] Well, likely wrong - I haven't got round to using Megaparsec yet.
You are right: https://github.com/mrkkrp/megaparsec/commit/ 750adb7c70392c3195eda12d816f4a1a2305321e
-- Özgür Akgün
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
-- Jeff Brown | Jeffrey Benjamin Brown Website https://msu.edu/~brown202/ Facebook https://www.facebook.com/mejeff.younotjeff LinkedIn https://www.linkedin.com/in/jeffreybenjaminbrown (InMail is unreliable) Github https://github.com/jeffreybenjaminbrown

I found the answer to my most recent question while reading this
tutorial[1] on megaparsec. Thanks, and apologies for the noise.
[1]
https://mrkkrp.github.io/megaparsec/tutorials/parsing-simple-imperative-lang...
On Sat, Sep 24, 2016 at 12:45 AM, Jeffrey Brown
I'm trying this again! The comment for Megaparsec.makeExprParser refers to "parens". When I grep for "parens" in Megaparsec I get only two occurences, both of them in comments:
./Lexer.hs:-- > parens = between (symbol "(") (symbol ")") ./Expr.hs:-- > term = parens expr <|> integer > "term"
If I try defining parens as in the comment from Lexer.hs, I get these errors:
<interactive>:37:33: Couldn't match type ‘Char’ with ‘()’ Expected type: [()] Actual type: [Char] In the first argument of ‘symbol’, namely ‘"("’ In the first argument of ‘between’, namely ‘(symbol "(")’ In the expression: between (symbol "(") (symbol ")")
<interactive>:37:46: Couldn't match type ‘Char’ with ‘()’ Expected type: [()] Actual type: [Char] In the first argument of ‘symbol’, namely ‘")"’ In the second argument of ‘between’, namely ‘(symbol ")")’ In the expression: between (symbol "(") (symbol ")")
[1] https://hackage.haskell.org/package/megaparsec-5.0.1/docs/ Text-Megaparsec-Expr.html
On Mon, Feb 29, 2016 at 2:05 AM, Özgür Akgün
wrote: On 29 February 2016 at 08:22, Stephen Tetley
wrote: For the expression parser, Megaparsec's documentation is wrong[*] and probably it should use symbol rather than reservedOp. Note that symbol is slightly different in Megaparsec as it's a plain combinator (rather than one instantiated from a first class module as in Parsec) so it takes two args rather than one.
[*] Well, likely wrong - I haven't got round to using Megaparsec yet.
You are right: https://github.com/mrkkrp/megaparsec/commit/750adb7c7 0392c3195eda12d816f4a1a2305321e
-- Özgür Akgün
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
-- Jeff Brown | Jeffrey Benjamin Brown Website https://msu.edu/~brown202/ Facebook https://www.facebook.com/mejeff.younotjeff LinkedIn https://www.linkedin.com/in/jeffreybenjaminbrown (InMail is unreliable) Github https://github.com/jeffreybenjaminbrown
-- Jeff Brown | Jeffrey Benjamin Brown Website https://msu.edu/~brown202/ Facebook https://www.facebook.com/mejeff.younotjeff LinkedIn https://www.linkedin.com/in/jeffreybenjaminbrown (InMail is unreliable) Github https://github.com/jeffreybenjaminbrown
participants (4)
-
Jeffrey Brown
-
Stephen Tetley
-
William Yager
-
Özgür Akgün