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 #273 ] Add more parenthesis in arguments of operators and sections #276

Merged
merged 2 commits into from
Feb 9, 2024

Conversation

jespercockx
Copy link
Member

Ideally, our pretty-printing library should insert parenthesis where needed. However, hs-src-exts does not insert adequate parenthesis for infix operators so we need to insert some by hand (see issues #54 and #273).

This also disables the printing of _- u as a right section (- u) in Haskell, as that would be interpreted as a negation instead.

Comment on lines 289 to 291
| a == hsx
, pp op /= "-" -- Jesper: no right section for minus, as Haskell parses this as negation!
-> Hs.RightSection () op b -- System-inserted visible lambdas can only come from sections
Copy link
Contributor

@omelkonian omelkonian Feb 9, 2024

Choose a reason for hiding this comment

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

Introducing \ section -> section - ... is quite ugly; why not use a left section on subtract = flip (-) instead?

            | a == hsVar x
            -> if pp op == "-" then -- no right section for minus, as Haskell parses this as negation!
                   Hs.LeftSection () (QConOp $ unQual "subtract") b 
                else
                   Hs.RightSection () op b
             -- System-inserted visible lambdas can only come from sections

Minor comments:

  1. No need for the intermediate variable hsx, just inline here
  2. No need to mention the name of the person writing the comment :P

Copy link
Member Author

Choose a reason for hiding this comment

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

For this PR I wasn't really looking at whether the output is pretty, just whether it is correct. But I agree that your version is prettier.

The variable hsx was already there, I didn't want to touch it since it's unrelated to this PR.

Writing my name in comments is a habit I got from working on Agda itself where it seems to be standard practice. I personally quite like these little bits of personality in the codebase :)

@omelkonian omelkonian merged commit 02f495c into agda:master Feb 9, 2024
7 checks passed
@jespercockx jespercockx added this to the 1.3 milestone Feb 23, 2024
@jespercockx jespercockx linked an issue Feb 23, 2024 that may be closed by this pull request
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.

snd $ compiles incorrectly
2 participants