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

Copy link
Copy Markdown
Collaborator

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

@Lysxia

Copy link
Copy Markdown
CollaboratorAuthor

Hm. Maybe I shouldn't touch Result.

@bergmark

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

Copy link
Copy Markdown
CollaboratorAuthor

OK!

@bergmarkbergmark 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 threadexamples/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 threadexamples/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
CollaboratorAuthor

Choose a reason for hiding this comment

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

OK!

Comment threadexamples/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
CollaboratorAuthor

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
CollaboratorAuthor

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
Copy Markdown
CollaboratorAuthor

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-errorsOctober 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-errorsOct 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 freeto 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

@Lysxia@bergmark@silky@fishtreesugar