Skip to content

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

Merged
merged 5 commits into from
Jan 9, 2022

Conversation

fsoikin
Copy link
Contributor

@fsoikin fsoikin commented Jan 7, 2022

Description of the change

More stack-safe sequence-dealing combinators (see #130 for context): many1Rec, sepByRec, sepBy1Rec, endByRec, endBy1Rec, chainrRec, chainr1Rec, chainlRec, chainl1Rec, skipManyRec, and skipMany1Rec


Checklist:

  • Added the change to the changelog's "Unreleased" section with a link to this PR and your username
  • Linked any existing issues or proposals that this pull request should close
  • Updated or added relevant documentation in the README and/or documentation directory
  • Added a test for the contribution (if applicable)

Comment on lines -195 to +238
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
Copy link
Contributor Author

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?

Copy link
Member

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.

Copy link
Member

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.

Copy link
Member

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.

Comment on lines -209 to +266
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
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Same here.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah.

@jamesdbrock jamesdbrock merged commit 22829f5 into purescript-contrib:main Jan 9, 2022
@jamesdbrock
Copy link
Member

a <- p
tailRecM go { last: a, init: Nil }
where
-- This looks scary at first glance, so I'm leaving a comment in a vain
Copy link
Member

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants