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

Fix lambda precedence #1470

Merged
merged 4 commits into from
Aug 26, 2023
Merged

Fix lambda precedence #1470

merged 4 commits into from
Aug 26, 2023

Conversation

xsebek
Copy link
Member

@xsebek xsebek commented Aug 26, 2023

Before (with #1459):

❯ cabal run swarm -O0 -- format <(echo '\\m. case m (\\x. x + 1) (\\y. y * 2)')
\m. case m \x. x + 1 \y. y * 2

After:

❯ cabal run swarm -O0 -- format <(echo '\\m. case m (\\x. x + 1) (\\y. y * 2)')
\m. case m (\x. x + 1) (\y. y * 2)

@xsebek xsebek requested a review from byorgey August 26, 2023 09:31
@xsebek xsebek self-assigned this Aug 26, 2023
Comment on lines +191 to +193
prettyPrec p t@(TLam {}) =
pparens (p > 9) $
prettyLambdas t
Copy link
Member Author

Choose a reason for hiding this comment

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

@byorgey I assume this is overly pessimistic - in the example case, only the inner lambda requires parentheses.

However, the least amount of parentheses might be harder to read. 😄

Copy link
Member

Choose a reason for hiding this comment

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

Hah, yes, in theory, a lambda at the very tail end of an expression does not need parentheses, but that would be annoying to read. I think this is fine.

Comment on lines +191 to +193
prettyPrec p t@(TLam {}) =
pparens (p > 9) $
prettyLambdas t
Copy link
Member

Choose a reason for hiding this comment

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

Hah, yes, in theory, a lambda at the very tail end of an expression does not need parentheses, but that would be annoying to read. I think this is fine.

@xsebek xsebek added the merge me Trigger the merge process of the Pull request. label Aug 26, 2023
@mergify mergify bot merged commit 64fe028 into main Aug 26, 2023
9 checks passed
@mergify mergify bot deleted the lambda-precedece branch August 26, 2023 17:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merge me Trigger the merge process of the Pull request.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Parameters to case are not formatted with parens
2 participants