So I am a bit confused as to how curried functions in Scala work. I have the following code which compiles, but I am not sure how!
def fixedPoint(f: Double => Double, initialGuess: Double) = {
//dummy impl, does nothing.
}
def averageDamp(f: Double => Double)(x: Double) = (x + f(x))/2
def sqrt(x: Int) = {
fixedPoint(averageDamp(y => x/y))(1)
}
This code compiles fine, but I would have thought averageDamp needs to also take another parameter? So it should be :
fixedPoint(averageDamp(y=> x/y)(1))(1)
But this does not compile, and i get a message saying type mismatch; found : Double required: Double ⇒ Double
The following does not compile, which makes sense:
val num = averageDamp(y => x/y)
This gives the compile error message : "missing argument list for method averageDamp in object Foo Unapplied methods are only converted to functions when a function type is expected."
So I am not sure why it compiles when calling averageDamp with one parameter inside the call to fixedPoint, but fails to compile when i call it on its own.
Any help would be great.