The compiler is able to provide evidence about type parameters, e.g:
def foo[A, B](implicit ev: A <:< B): B
A look at the type definition for <:< in Predef shows
sealed abstract class <:<[-From, +To] extends (From => To) with Serializable
private[this] final val singleton_<:< = new <:<[Any,Any] { def apply(x: Any): Any = x }
implicit def $conforms[A]: A <:< A = singleton_<:<.asInstanceOf[A <:< A]
- Can anyone explain the implicit resolution chain here? How can
$conforms[A]: A <:< Aconvince the compiler to create an instance of<:<[List[String], Seq[String]]for instance? Or<:<[Dog, Animal]. And what happens if (when) the.asInstanceOfcall throws an exception? - Why is the subclassing of
=>necessary?