-
Notifications
You must be signed in to change notification settings - Fork 50
More stack-safe combinators #131
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
Conversation
chainl1' :: forall m s a. Monad m => ParserT s m a -> ParserT s m (a -> a -> a) -> a -> ParserT s m a | ||
chainl1' p f a = | ||
( do | ||
f' <- f | ||
a' <- p | ||
chainl1' p f (f' a a') | ||
) <|> pure a | ||
chainl1' a | ||
where | ||
chainl1' a = | ||
( do | ||
f' <- f | ||
a' <- p | ||
chainl1' (f' a a') | ||
) <|> pure a |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I moved this under where
, because it seems like a private helper function. Technically it might be breaking though, if anybody happens to use this function for some reason. Should it be added to changelog? Or would you prefer it be brought back to the top level?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, technically it is breaking, isn't it.
I'll add this to the changelog and we'll bump major version to 8.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like this private helper function has been exported since 2014, when this file was renamed from something else.
I agree that this is a private helper function and it should be private.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's better this way, thanks.
chainr1' :: forall m s a. Monad m => ParserT s m a -> ParserT s m (a -> a -> a) -> a -> ParserT s m a | ||
chainr1' p f a = | ||
( do | ||
f' <- f | ||
a' <- chainr1 p f | ||
pure $ f' a a' | ||
) <|> pure a | ||
chainr1' a | ||
where | ||
chainr1' a = | ||
( do | ||
f' <- f | ||
a' <- chainr1 p f | ||
pure $ f' a a' | ||
) <|> pure a |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah.
a <- p | ||
tailRecM go { last: a, init: Nil } | ||
where | ||
-- This looks scary at first glance, so I'm leaving a comment in a vain |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I love this explanation, thanks very much for this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
Description of the change
More stack-safe sequence-dealing combinators (see #130 for context):
many1Rec
,sepByRec
,sepBy1Rec
,endByRec
,endBy1Rec
,chainrRec
,chainr1Rec
,chainlRec
,chainl1Rec
,skipManyRec
, andskipMany1Rec
Checklist:
Linked any existing issues or proposals that this pull request should closeUpdated or added relevant documentation in the README and/or documentation directory