When using the <|> combinator in a Parsec or Megaparsec parser, 'try' maybe needed to force backtracking in case the first parser fails having consumed input. In Parsec I need to use 'try' when parsing strings:
λ: parse (try (string "abc") <|> string "abd") "" "abd"
Right "abd"
Without the 'try', the parse fails as the first parser consumes the 'a', leaving just 'bd' for the second parser which then naturally fails as well.
In Megaparsec, the 'try' is not needed:
λ: parse (string "abc" <|> string "abd") "" "abd"
Right "abd"
and so somehow in Megaparsec the string parser helpfully does not consume input when it fails.
My questions are:
How might I have found out, other than experimenting, that the string parser behaviors are different between Parsec and Megaparsec - I have no seen it documented?
How can I easily (that is, without experimentation) tell in general whether a parser consumes input if it fails?
Thank you.