关于scala中隐式示例的困惑

Confusion about implicit example in scala

implicit def list2ordered[A](x: List[A])(implicit elem2ordered: A => Ordered[A]): Ordered[List[A]] =
  new Ordered[List[A]] {
    //replace with a more useful implementation
    def compare(that: List[A]): Int = 1
}

println(List(1,2,3) <= List(4,5))

无法理解它是如何工作的

List(1,2,3) <= List(4,5)

脱糖为

list2ordered(List(1, 2, 3))(Predef.intWrapper) <= List(4, 5)

list2ordered

的签名
implicit def list2ordered[A](x: List[A])(implicit elem2ordered: A => Ordered[A]): Ordered[List[A]]

表示它是一个conditional implicit conversion,也就是说,你有一个隐式转换List[A] => Ordered[List[A]],前提是你有一个隐式转换A => Ordered[A]

Predef.intWrapper正是这样一种隐式转换,因为它是Int => RichIntRichInt扩展了Ordered[Int](RichInt <: ScalaNumberProxy[Int] <: OrderedProxy[Int] <: Ordered[Int]).

can 总能看到 reify

是如何解决隐式问题的
import scala.reflect.runtime.universe._
println(reify{List(1,2,3) <= List(4,5)}.tree)
//App.this.list2ordered(List.apply(1, 2, 3))(((x) => Predef.intWrapper(x))).$less$eq(List.apply(4, 5))