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

Combinator for accumulative errors #592

Merged
merged 4 commits into from
Oct 10, 2017
Merged

Conversation

Lysxia
Copy link
Collaborator

@Lysxia Lysxia commented Sep 27, 2017

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

@Lysxia
Copy link
Collaborator Author

Lysxia commented Sep 28, 2017

Hm. Maybe I shouldn't touch Result.

@bergmark
Copy link
Collaborator

bergmark commented Oct 5, 2017

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
Copy link
Collaborator Author

Lysxia commented Oct 8, 2017

OK!

Copy link
Collaborator

@bergmark bergmark left a comment

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?

@@ -8,6 +8,7 @@ import Prelude.Compat

Copy link
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

@@ -39,3 +40,6 @@ main = do
print req
let reply = Coord 123.4 20
BL.putStrLn (encode reply)
let asCoord :: f Coord -> f Coord
Copy link
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
Collaborator Author

Choose a reason for hiding this comment

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

OK!

@@ -28,9 +29,9 @@ instance ToJSON Coord where
-- should match the format used by the ToJSON instance.

instance FromJSON Coord where
parseJSON (Object v) = Coord <$>
Copy link
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
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.

@@ -333,6 +340,22 @@ apP d e = do
return (b a)
{-# INLINE apP #-}

-- | 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
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
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
Copy link
Collaborator Author

Lysxia commented Oct 9, 2017

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
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
Copy link
Contributor

silky commented Aug 8, 2024

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

@fishtreesugar
Copy link
Contributor

#597

@silky
Copy link
Contributor

silky commented Aug 9, 2024

@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