-
Notifications
You must be signed in to change notification settings - Fork 81
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
Against space in record updates and record patterns #565
Comments
I always assumed that Does anybody have relevant experience / feedback from people? (Personally I prefer |
Right now spacing of |
|
The fact that |
Just to share this experience, I spent a long time fixing this manually every time I ran Ormolu. Of course, it got exhausting. My solution was finally to add parentheses around record syntax in parameters. That clarifies the precedence just as well. It's a little more noisy, but I think it's worth it given that the precedence is obviously wrong in the first place. I definitely recommend just adding the parentheses, after which the extra space doesn't really matter. |
The problem with this is that some people can't stand unnecessary tokens in code, and scoff at extraneous parentheses. "Did you know that record update has higher precedence than function application?", yes, yes, I know that. Otherwise I like this solution, but I'd like the space to go away even more. "[...] makes it clear and unambiguous" — only for people who know subtleties of the Haskell grammar. |
I believe this issue would break ormolu's support for record-dot-preprocessor syntax which uses the space to differentiate desugaring. |
I suppose that preprocessor should be deprecated as soon as this accepted proposal is implemented in ghc though. |
@Avi-D-coder I don't think so. This issue is about the space between a variable or constructor name and a |
Your right I miss read it. |
@cdsmith the space is used to determine if the record update is done via a HasField instance or not, see the last paragraph here. I'm pretty sure the accepted GHC proposal always uses HasField and there is no whitespace-sensitivity there, right? Interestingly, when supporting the preprocessor, Ormolu already has to preserve the non-existence of whitespace before the |
@cjay Yes, I see you're right. |
Currently, Ormolu always seems to format record updates and patterns with a space between the record data constructor or variable and the
{
like this:foo {bar}
instead of alternatives likefoo{ bar }
orfoo{bar}
.This has the disadvantage that the
{}
part looks like an additional function parameter when used in function calls or pattern matches in function definitions, which is especially confusing to newbies:foo a {b} c -- function call: looks like 3 parameters but is actually 2
foo Bar {baz} blerg = ... -- same with pattern match in function definition
Personally, I prefer
foo{ bar }
. It makes visually clear that the{}
part belongs to the preceding identifier, while having superior readability compared tofoo{bar}
. Side note, it is only one character longer than the currentfoo {bar}
.If there are good reasons for this design decision, it would be nice to have them collected in the design document, or at least in this issue.
The text was updated successfully, but these errors were encountered: