-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Should the wide arrow in match-case be dropped? #5119
Comments
The argument presented here seems compelling to me. In other contexts, we use At some point in the future, it might be reasonable to use let n: i32 = match (F()) { case 0 => 5, case _: i32 => 10 }; ... but using it to introduce a block of code seems inconsistent. If the parens in fn F() -> something { case something { This would mean that we can't we support a non-expression pattern syntax of the form |
Thanks for the reply! Glad you found it compelling :) I was under the impression that we were intending the parens in case to be mandatory. Especially in the face of so-called "guards" that can come after the case.
@geoffromer Can you speak to the use of guards and how that interacts with the wide arrow and case-mandated parens? |
Ah, I see now there is code that does not have parens in the case, as in carbon-lang/explorer/data/prelude.carbon Line 209 in c7a338b
|
I worry that if parens are not mandatory, the lack of wide arrow will be ambiguous w/r/t struct literals versus the body of the case.
|
I think that's exactly analogous to fn F() -> {} { return 10; } ... which is parseable (at least by machines; humans are another question), because we don't have any expression suffixes starting with |
Summary of issue:
New Information: The syntax for match-case was chosen before the syntax of lambdas was designed. Since then, lambdas landed in the language in #3848. This means the syntax of lambdas could potentially justify reconsidering the syntax of match-case.
Issue: The arrow in a case of match-case uses the
=>
syntax followed by a curly braced body. This is incongruent to the syntax of all function kinds, with the lambdas proposal landed. The "wide arrow" means a function returnsauto
deduced from a single-expression body followed by a semicolon.Leads Question: Would it be ok to drop the wide arrow entirely from the match-case syntax? Assuming the parens are mandatory regular parens, as suggested in #5118, there shouldn't be any syntactic ambiguities if match-case was written like the following:
Details:
No response
Any other information that you want to share?
No response
The text was updated successfully, but these errors were encountered: