This says that 'sum' is a function that take a function (the argument 'f') that takes an Int parameter and returns an Int result;], and the function 'sum' returns a function of type "(Int, Int)=> Int)". In other words, 'sum' is a function factory that takes one function as its argument, and it generates a function that takes two Ints (and returns an Int).

One way to use sumF would be to do something like:

def g = sum((x) => x * x)
g(1,3)

... which calls 'sum' to generate a function that sums squares, naming the new function 'g', and then calls 'g' with 1 and 3 as parameters.

Sometimes Scala can't really tell that this is what you are trying to do, and it complans in your def of g. You solve that problem like so:

def g = sum((x) => x * x) _
g(1,3)

... which uses the trailing underscore to tell Scala, "Hey! Don't worry -- this call of 'sum' just returns a function and I promise to pass the right arguments to that function when I call it. (I think.)

<pFor the ultimate in brevity, you can define g and call it in a single line:</p>

sum(x => x * x)(1, 10)

The "sum(x => x * x)" generates the new (unnamed) function and the "(1, 10)" calls it with the arguments 1 and 10.