@ def foo()()()()() = 1 defined function foo @ foo res1: Int = 1 @ foo() res2: Int = 1 @ foo()() res3: Int = 1 @ foo()()()()() res4: Int = 1 @ foo()()()()()() cmd5.sc:1: Int does not take parameters val res5 = foo()()()()()() ^ Compilation Failed @
This is something that has annoyed me about Scala since forever, and is a major contributor to my initial confusion learning the language (Nine ways to define a method in Scala?).
I only know of Ruby which lets you include-or-leave-out parentheses at-will when calling methods, which probably isn’t a good example for a statically-typed language to follow…
Put another way, in the above example,
foo is an
() => Int
() => () => Int
() => () => () => Int
() => () => () => () => Int
() => () => () => () => () => Int
All at the same time! And Scala is supposed to be a strongly-typed language…
Does anyone actually like this behavior? Is there a chance that we could get rid of it in Dotty?