In addition to the @Nathan Hughes answer, if you want to pass the different argument to the sum function on each call you need to change your sq method like
def sq (x: Int, y: Int, f: (Int, Int)=> Int): (Int, Int)=> Int = { x + y * f(_: Int, _:Int) }
Insted of expecting the int from the sq method return partially applied function of type (Int, Int) => Int from `sq' then pass other argument to that function like,
sq(10, 20, sum)(1, 2) // 1st approach //2nd approach would be //You can hold the function in another variable and call that function with other arguments val partialSum = sq(10,20, sum) partialSum(1, 2)
and you will get your result.
Or if you still want that sq method should return Int, you can define your sq method like
def sq (x: Int, y: Int, f: (Int, Int)=> Int)(a:Int, b:Int):Int = { x + y * f(a, b) } scala> sq(10,20, sum)(1,2) res2: Int = 70
def sq (x: Int, y: Int, z: Int): Int = x + y +z?aandbare the names to be used inside the functionsum. You are going to pass valuesx,yasa,b; hencexandywill take place ofaandbin function call. so yoursqwill bex + y * f(x, y)(if you want square then(x + y) * f(x, y)) and you will callsqassq(x, y, sum). Actually you don't even need to define thoseval x = 7andval y = 9. You can directly usesq(7, 9, sum).sqshould do? How it should usef?xandyas method parameter names and as variables defined outside the method, this is confusing to understand what you really want to do