The following code works:
def bbb(v: Double => Unit)(a: Double): Unit = v(a)
bbb{v: Double => v == 0 }(5)
bbb{v: Double => Array(v) }(5)
But if I overload bbb
as follows, it doesn't work unless I manually assign the type signature for the first bbb
call:
def bbb(v: Double => Unit)(a: Double): Unit = v(a)
def bbb(v: Double => Array[Double])(a: Double): Array[Double] = v(a)
bbb{v: Double => v == 0 }(5) // bbb{(v => v == 0):(Double => Unit)}(5)
bbb{v: Double => Array(v) }(5)
I think this is related to implicit conversions. In the first case, when you only have a definition that results in a Unit, even though you get results such as Boolean or Array, an implicit conversion to Unit is triggered returning you always the expected Unit.
When you overload, this implicit conversion is no longer applied, but the overloading resolution mechanism instead. You can find how this works in more detail in the Scala Language Specification
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With