I think this has to be allowed, if it isn’t ambiguous.
The reason is that refactoring from a one-liner to multi-liner is important.
If I have the braces/parens already, why would I remove them just to go multi-line? It’s an extra hassle. It’s as easy, and less ambiguous, to keep them.
So, that means if we want to be able to write
foo: x =>
bar(x)
we should allow
foo: x => bar(x)
Note that anything that works on xs.map
should work on foo()
alone, so I’ve listed that case to highlight the potential for ambiguity.
This is the troublesome one to my eyes:
val bippy = foo: x => f(x)
val quoxo = (foo: x) => g(foo)
val snyth = (foo: x => f(x))
In the first case you have function application; in the second, you have type ascription; in the third you have function application again.
This is why I yet again argue for ...
or somesuch to generically open an indentable block. It’s completely unambiguous:
val bippy = foo ... x => f(x)
But, failing anything more adventurous like this, I think requiring the :
is better than not.
I won’t likely be using the feature anyway, because of the visual ambiguity, but I think the regularity of having :
is probably better. Still, since I’m probably opting out, don’t listen to me.
I do think it’s better to do something than nothing; I do think brace-free is great for short blocks as it is; and I never use the :
-ending forms anyway because it’s confusing. Right now, that’s the only way to generate confusion, but if this also provides a way to be confusing, well, I can just not use this one too!
However, the lack of consistency in being able to elide braces is I think moderately worse than the inconsistencies and edge-cases introduced by a proposal like this. So I am in favor of something.