I want to set a default value to variable. But my Scala compiler says:
Error:(20, 16) unbound placeholder parameter
val p: T = _
^
Here is the code.
object InverseFunctionsExample extends App {
type D = Double
def f(x: D): D = 5 * x + 10
def g(x: D): D = 0.2 * x - 2
printMessage(isInversible(f, g))
def printMessage(inv: Boolean): Unit = {
if (inv) print("YES!") else print("NOPE!")
}
def isInversible[T](f: (T) => T, g: (T) => T): Boolean = {
val p: T = _
if (f(p) == g(p))
true
else
false
}
}
Is it possible to initialize a val p
with default value somehow?