Is there a built-in or parser in the Parsec library?

I'm looking for a parser that will try to use the first parser, and will return Left a

if it succeeds, or if it doesn't work, try the second parser and return Right b

. In other words, something with a signature:

Parser a -> Parser b -> Parser (Either a b)

      

Where, for example, type Parser a = P.Parsec String () a

It's not particularly hard to implement this yourself:

parseEither pa pb = (Left <$> pa) <|> (Right <$> pb)

      

But it seems to be such a useful and trivial construct that I was wondering if something like this already exists in the Parsec library.

+3
haskell parsec


source to share


No one has answered this question yet

See similar questions:

five
Haskell constructor aliases

or similar:

sixteen
Haskell / Parsec: how to use Text.Parsec.Token with Text.Parsec.Indent (from indentation package)
6
Why is only the first given infix statement processed when using Parsec buildExpressionParser?
five
Why does the Parsec Choice operator seem to depend on the order of the parsers?
4
How do I parse this grammar in Parsec? (unusual case of left recursion)
3
Defining a new primitive combinator in Parsec
3
In Parsec, fixing a broken token before collecting the parser
2
How do I store the result of a parsec in a list in Haskell?
2
Preserving the Parser Failure Mode in Parsec
0
Parsec hangs on file input
0
How to throw an error during the manyAccum parser



All Articles
Loading...
X
Show
Funny
Dev
Pics