Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consider adding a version of parseWith with a more informative type #106

Open
treeowl opened this issue Sep 8, 2015 · 1 comment
Open

Comments

@treeowl
Copy link

treeowl commented Sep 8, 2015

parseWith runs a parser and returns a Result. This Result will always be either Done or Fail, but the type leaves open the possibility of Partial. This means that library users must add "can't happen" errors for Partial, and some may get confused and think they need to do something in that case. I think it might make sense to add types IFinalResult and FinalResult or similar to represent a result known not to be partial. Then we could add a function to produce that:

parseWith' :: Monad m =>
             (m B.ByteString)
          -> I.Parser a
          -> B.ByteString
          -> m (FinalResult a)
parseWith' refill p s = step $ parse p s
  where
        step (T.Partial k) = (step . k) =<< refill
        step (T.Done i r) = return (Done' i r)
        step (T.Fail i contexts err) = return (Fail' i contexts err)

Yes, this will probably allocate an extra Done' constructor, at least sometimes, but I still think it's worth having.

@chris-martin
Copy link
Contributor

chris-martin commented Jan 9, 2023

I've just released a new package which adds some of the types that Attoparsec is missing, including FinalResult: https://hackage.haskell.org/package/attoparsec-run

Would be happy to submit a PR to Attoparsec and deprecate my package, if there were any indication that changes would be accepted. Since I haven't been able to get simple metadata corrections released here, I figured I should just go ahead and release on my own for now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants