Consider adding a version of `parseWith` with a more informative type
- Dominant language
- Haskell
- Stars
- 531
- Forks
- 98
- PR merge metrics
- No merged PRs in 30d
Description
`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:
``` haskell
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.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.