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

Avoid extra parens for wildcard type signature #2764

Merged
merged 1 commit into from
Mar 9, 2022

Conversation

xsebek
Copy link
Contributor

@xsebek xsebek commented Mar 8, 2022

Avoid parentheses in simple cases (a, Char, (),...).

The good news is, that getting types inside tuples and lists will not force you to apply hint "Redundant brackets":

g :: a -> _
g x = (x, const x)
--------------------------
-- before
g :: a -> ((a, b -> a))
--------------------------
-- after
g :: a -> (a, b -> a)

The caveat is that it is still context unaware (works on text only) and the common use case of f :: _ is not improved.

@xsebek xsebek requested a review from pepeiborra as a code owner March 8, 2022 00:02
@michaelpj
Copy link
Collaborator

Could you add some tests for the examples you give in the PR description?

Copy link
Collaborator

@michaelpj michaelpj left a comment

Choose a reason for hiding this comment

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

LGTM modulo adding some tests.

@xsebek
Copy link
Contributor Author

xsebek commented Mar 9, 2022

@michaelpj there are now tests for the tuple, list and unit type. 🙂

+ avoid parens in simple cases (a, Char, [a], (),...)
- change one test - (Int)/Int
@xsebek
Copy link
Contributor Author

xsebek commented Mar 9, 2022

(circleci did not finish so I rebased on master to give it a second chance)

[ "func :: _"
, "func x y = x + y"
]
[ "func :: (Integer -> Integer -> Integer)"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Hmmm, I guess it's not easy to tell if the hole is the entirety of the type signature? That seems like the remaining slightly bad case, and also probably a relatively common one...

Copy link
Collaborator

Choose a reason for hiding this comment

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

Anyway, that can be future work.

@michaelpj michaelpj merged commit 8a90def into haskell:master Mar 9, 2022
@AndreasPK
Copy link

Thanks for this!

July541 pushed a commit to July541/haskell-language-server that referenced this pull request Mar 30, 2022
+ avoid parens in simple cases (a, Char, [a], (),...)
- change one test - (Int)/Int

Co-authored-by: Ondrej Sebek <[email protected]>
sergv added a commit to sergv/haskell-language-server that referenced this pull request May 26, 2022
sergv added a commit to sergv/haskell-language-server that referenced this pull request May 26, 2022
sergv added a commit to sergv/haskell-language-server that referenced this pull request May 26, 2022
michaelpj pushed a commit that referenced this pull request May 27, 2022
* Omit more parens for wildcard type signature (#2929)

This is a followup to #2764.

* Review suggestions
hololeap pushed a commit to hololeap/haskell-language-server that referenced this pull request Aug 26, 2022
* Omit more parens for wildcard type signature (haskell#2929)

This is a followup to haskell#2764.

* Review suggestions
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.

Use type signature: Don't insert excess parentheses .
3 participants