In the below code excerpt, the last statement does not compile. However, the statement immediately before that one does in fact compile. This second-to-last statement is what I would expect the compiler would convert the last statement to. I do not understand why it does not work. Any help is appreciated.
trait ParameterizedBy[A, B] {
val parameterized: B
}
object ParameterizedBy {
implicit def toParameterized[A, B, C](p: ParameterizedBy[A, B])(
implicit f: B => C): C = f(p.parameterized)
}
trait Wraps[A] {
val wrapped: A
}
object Wraps {
implicit def toWrapped[A](w: Wraps[A]): A = w.wrapped
}
val p = new ParameterizedBy[String, Wraps[Int]] {
override val parameterized: Wraps[Int] = new Wraps[Int] {
override val wrapped = 6
}
}
ParameterizedBy.toParameterized(p)(Wraps.toWrapped) + 5
p + 5