anoma / juvix

A language for intent-centric and declarative decentralised applications
https://docs.juvix.org
GNU General Public License v3.0
442 stars 54 forks source link

Make curly braces in `case` optional #2769

Closed lukaszcz closed 1 month ago

lukaszcz commented 1 month ago

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 commented 1 month ago

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.