While technically this is possible:
type Handled[S, R] = S => R
def defaultHandled[S, R](x: S): R = x.asInstanceOf[R]
def myFunc[S, R](value: S, handled: Handled[S, R] = defaultHandled[S, R] _): R = {
handled(value)
}
myFunc[Int, Int](1)
It's not type safe and generally not a good idea. For example, if you try to call myFunc with different type parameters while still relying on default handled value, you'll get runtime exception:
myFunc[Int, String](1)
java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.String
Scala way to address this is to have handled as implicit parameter. In this case you can supply default implementation which compiler will use it possible.
type Handled[S, R] = S => R
implicit def defaultHandled[S]: Handled[S, S] = identity
def myFunc[S, R](value: S)(implicit handled: Handled[S, R]): R = {
handled(value)
}
myFunc(1) // compiles and works
myFunc[Int, String](1) // compilation error: Error:(11, 21) No implicit view
// available from Int => String.
//myFunc[Int, String](1)
// ^