In Scala invoking no-parameter function with and without brackets is executed in different way
currying, scala
Solution
Look at the type of `fun`, it's `fun: () => Unit`. You can think of that as meaning that when you call it with `()`, you get `Unit` in return. Without explicitly calling it, `fun` refers to the function as a value, not the result of calling it. This is the essence of the concept of higher-order functions.
If it had type `fun: => Unit`, simply mentioning `fun` would cause it to be executed, in which case there would be no way to refer the function as a value.
Problem
I have following Currying function declaration: ``` def logString(count: Int)(fun:() => Unit) { for (n <- 1 to count) { fun } } ``` I call this function in this way: ``` logString(3) { () => print("I") } ``` The result is nothing - just no output. Then I just add brackets after "fun" function invocation, inside the body of Currying function declaration: ``` def logString(count: Int)(fun:() => Unit) { for (n <- 1 to count) { fun() } } ``` The result becomes what is expected: III Is this some Scala bug, or there is some rule that I missed when learning Scala? I know that there is rule that when you declare function like this: def myFun = 1 we can not invoke it with brackets - the compilation fails. But having different results when invoking a function with and without brackets seems more like a bug. Am I right or I miss something about Scala?