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

Make curly braces in case optional #2769

Closed
lukaszcz opened this issue May 7, 2024 · 1 comment · Fixed by #2778
Closed

Make curly braces in case optional #2769

lukaszcz opened this issue May 7, 2024 · 1 comment · Fixed by #2778
Assignees

Comments

@lukaszcz
Copy link
Collaborator

lukaszcz commented May 7, 2024

In the issue

I originally proposed to have the braces in case expression optional -- to be used only for disambiguation with nested cases avoiding the awkward parentheses around the nested case. However, non-nested cases are the most common use-case. A syntax without braces seems to fit better with the overall feel of the language. We don't have braces in let or type.

I think this issue resurfaces now with the implementation of multi-way if, where braces are neither planned nor needed:

To keep the syntax consistent, allowing to omit braces in case would make sense. Also, in the most common situation braces in case are not necessary - omitting them would make the syntax more concise. We would keep the option to have them only for disambiguation of nested cases.

Hence, I propose to allow also

case x of
| pat1 := expr1
| pat2 := expr2

in addition to

case x of {
| pat1 := expr1
| pat2 := expr2
}

This poses no problems in parsing -- we have two possibilities which can be distinguished by one lookahead token ({). I imagine one would normally use the version without braces, except to disambiguate a nested case.

@lukaszcz
Copy link
Collaborator Author

lukaszcz commented May 8, 2024

We should clean up and fix the case syntax. I see the old case syntax without braces but also without of is still supported. We should decide on a more uniform syntax, and remove the old syntaxes. My proposal is above.

@lukaszcz lukaszcz self-assigned this May 13, 2024
paulcadman pushed a commit that referenced this issue May 22, 2024
* Closes #2769 
* Removes old case syntax
* Pretty printing doesn't print braces in `case` if the `case` is a
"top" expression in a definition.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant