The scala language specification, section 7.2 is about implicit scope:
It explains that implicit scope are the modules associated in some way with the parts of type T
. What the parts of T are is listed below. One of those points is
if
T
denotes an implicit conversion to a type with a method with argument typesT1,…,Tn
and result typeU
, the union of the parts of T1,…,Tn and U;
I can't make head or tails from this. I don't understand how a type T can denote an implicit conversion.
What is meant by this part of the specification of implicit scope?
I believe this is referring to the following situation
case class Foo(v: Int)
object Foo {
implicit def stringToFoo(s: String) = Foo(42)
}
def f[A](v: A)(implicit ev: A => Foo) = ev(v)
f("woohoo")
where the implicit conversion type T = A => Foo
, and Foo
is the part associated with type parameter A
, therefore object Foo
becomes part of the implicit scope and stringToFoo
implicit conversion is resolved without needing an import.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With