[Haskell-cafe] attoparsec and backtracking

Roman Cheplyaka roma at ro-che.info
Sat Mar 16 09:40:08 CET 2013


* Niklas Hambüchen <mail at nh2.me> [2013-03-16 03:49:29+0000]
> I would agree that what attoparsec does for <|> of Alternative and mplus
> for MonadPlus is correct since e.g. the mplus laws say that a failure
> must be identity and therefore the following alternatives must be
> considered. I also find it very convenient that attoparsec works this
> way, and prefer it to what parsec does by default.

empty/mzero are indeed identities in Parsec.

What doesn't hold is the law

   v >> mzero = mzero

But this one is often violated:

  > flip runState 0 $ runMaybeT mzero
  (Nothing,0)

  > flip runState 0 $ runMaybeT $ lift (modify (+1)) >> mzero
  (Nothing,1)

Roman



More information about the Haskell-Cafe mailing list