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

[acc-errors] Accumulate errors for Seq and Vector parsers #600

Open
wants to merge 4 commits into
base: acc-errors
Choose a base branch
from

Conversation

bergmark
Copy link
Collaborator

Naming has room for improvements, maybe we should even have a module for accumulation related functions, or should we do this in some other way like using a newtype so we can have proper traversable instances (not sure if that'll work out)?

Ping @Lysxia


accumulateTraverseVector :: (a -> Parser b) -> Vector a -> Parser (Vector b)
accumulateTraverseVector f v =
if V.null v
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder, if it makes sense to define

newtype AccParser a = AccParser { runAccParser :: Parser a }

instance Applicative AccParser where
    AccParser f <*> AccParser x = AccParser (f <*>+ x) -- !!!

and use it, and not re-implement traverse for everything.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, it's a good idea to use Traversable here. Reexporting Parser versions that use AccParser under the hood is nice too.

@bergmark
Copy link
Collaborator Author

I'm not sure when I'll get around to playing more with this, so feel free to steal the commit if anyone wants to keep going before I get the chance.

@bergmark
Copy link
Collaborator Author

I changed this to use an AccParser newtype, much nicer!

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

Successfully merging this pull request may close these issues.

3 participants