Skip to content

Combinator for accumulative errors#592

Merged
bergmark merged 4 commits into
haskell:acc-errorsfrom
Lysxia:acc-errors
Oct 10, 2017
Merged

Combinator for accumulative errors#592
bergmark merged 4 commits into
haskell:acc-errorsfrom
Lysxia:acc-errors

Conversation

@Lysxia

@Lysxia Lysxia commented Sep 27, 2017

Copy link
Copy Markdown
Collaborator

This defines a liftP2 accumulating errors from both branches. Resolves #578.

@Lysxia

Lysxia commented Sep 28, 2017

Copy link
Copy Markdown
Collaborator Author

Hm. Maybe I shouldn't touch Result.

@bergmark

bergmark commented Oct 5, 2017

Copy link
Copy Markdown
Collaborator

Very cool, thanks!

I think I agree that we shouldn't change Result for backwards compat, but it can be up for discussion. Are there a lot of exposed functions that would need to be duplicated? Should we leave just some of them with the old result type?

@Lysxia

Lysxia commented Oct 8, 2017

Copy link
Copy Markdown
Collaborator Author

OK!

@bergmark bergmark left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

  • I think we should have some tests for error accumulation by itself
  • Does this affect performance?

I suppose one of the next steps would be to do this accumulation for built-in instances and TH/Generics? That should help us check the API and performance.

I'm thinking about how to release this and continue development... How about merging this into a branch first?

Comment thread examples/Simplest.hs
@@ -8,6 +8,7 @@ import Prelude.Compat

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

With the example name "Simplest" I think we should keep this file as it is, but we can add a SimplestWithErrorAccumulation instead and add comments/references in this file

Comment thread examples/Simplest.hs
print req
let reply = Coord 123.4 20
BL.putStrLn (encode reply)
let asCoord :: f Coord -> f Coord

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

For an example I think it would be clearer to skip asCoord and write a type annotation around verboseDecode instead.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

OK!

Comment thread examples/Simplest.hs
-- should match the format used by the ToJSON instance.

instance FromJSON Coord where
parseJSON (Object v) = Coord <$>

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Is it possible to write this in the f <op> x <op> y <op> z style? It might not be better but I'm curious!

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Sure! Coord <$> v .: "x" <*>+ v .: "y" should work.


-- | A variant of 'Control.Applicative.liftA2' that lazily accumulates errors
-- from both subparsers.
liftP2 :: (a -> b -> c) -> Parser a -> Parser b -> Parser c

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I'm personally not a fan of the name liftA2, what do you think? Can you think of a better name?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I can't think of a better name, but we could also just remove it. It is quite redundant with (<*>+).

@Lysxia

Lysxia commented Oct 9, 2017

Copy link
Copy Markdown
Collaborator Author

I'd be fine with taking the time to see the performance implications in a separate branch.

@bergmark bergmark changed the base branch from master to acc-errors October 10, 2017 12:57
@bergmark

Copy link
Copy Markdown
Collaborator

Cool let's do that, i'll file a PR against master to keep track of everything.

@bergmark bergmark merged commit f821ec4 into haskell:acc-errors Oct 10, 2017
@silky

silky commented Aug 8, 2024

Copy link
Copy Markdown
Contributor

Does anyone know why this code got removed? I've been looking for it 🥲 🥲 🥲

@fishtreesugar

Copy link
Copy Markdown
Contributor

#597

@silky

silky commented Aug 9, 2024

Copy link
Copy Markdown
Contributor

@fishtreesugar that doesn't quite clarify, as @Lysxia actually already merged his fixes before that.

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.

4 participants