[Haskell-cafe] The 13-line example in Text.Megaparsec.Expr
Jeffrey Brown
jeffbrown.the at gmail.com
Sat Feb 27 04:08:29 UTC 2016
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-Expr.html
--
Jeffrey Benjamin Brown
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20160226/86e3c897/attachment.html>
More information about the Haskell-Cafe
mailing list