Eta expansion corner case?

Hello,

In Scala 2 we can currently do this:

scala> :type scala.math.pow
(Double, Double) => Double

scala> val square = scala.math.pow(_, 2)
val square: Double => Double = Lambda$8219/1817381934@30eec548

scala> square(3)                                   
val res14: Double = 9.0

Is the above example going to be affected by the Scala 3 changes to eta expansion? https://dotty.epfl.ch/docs/reference/changed-features/eta-expansion.html. i.e. in Scala 3, will we be able to achieve the same without using an underscore?

I am thinking that the answer is no, that we will continue to have to use the underscore, because the following attempt to do away with the underscore doesn’t seem to work:

scala> val square: Double => Double = scala.math.pow(2)                                   
1 |val square: Double => Double = scala.math.pow(2)
  |                               ^^^^^^^^^^^^^^^^^
  |missing argument for parameter y of method pow: (x: Double, y: Double): Double

Would I be right in thinking that?

Thanks,

Philip

Actually, the above error I get is entirely predictable (that teaches me not to post such a message first thing in the morning, before having thought about it a bit more while having a shower) : how can the compiler be expected to know which of the two Double parameters I intended to omit! I guess it could reason that I want to omit the second one, in which case, if I wanted to omit the first parameter I would still have to use the underscore approach.

You’ll need to keep using the underscore.
This is not something Eta expansion will do. pow takes 2 parameters so can be ETA expanded to a (Double, Double) => Double, but not partially as a Double => Double => Double like you’re trying to do with pow(2)

1 Like

@dhoepelman thank you