Open
Description
Compiler version
3.6.0, 3.7.0, 3.7.1-RC2
Minimized code
//> using scala 3.7.0
trait Vectoric[V] {
def components: Array[V => Double]
def map(a: V)(f: Double => Double): V
}
trait VectoricOps {
extension [V: Vectoric as v](lhs: V) {
def map(f: Double => Double): V = v.map(lhs)(f)
def toArray: Array[Double] = v.components.map(c => c(lhs))
}
}
Output
[error] .\Main.scala:11:56
[error] parameter c does not take parameters
[error] def toArray: Array[Double] = v.components.map(c => c(lhs))
[error] ^
[error] .\Main.scala:11:63
[error] No given instance of type Vectoric[Array[V => Double]] was found for parameter v of method map in trait VectoricOps
[error] def toArray: Array[Double] = v.components.map(c => c(lhs))
[error]
Expectation
The code should compile. The same code compiles when using extension [V](lhs: V)(using v: Vectoric[V])
Maybe my expectation is wrong and the two forms are not equivalent, in which can I would be glad if anyone can explain the difference.
Note
There is no error when I remove the map
method from VectoricOps
extension.
The same error is produced when using:
extension [V: Vectoric](lhs: V) {
def map(f: Double => Double): V = ???
def toArray: Array[Double] = summon[Vectoric[V]].components.map(c => c(lhs))
}