To paraphrase the title question, are implicit parameters to a function implicit values within the function's scope?
Here's a small test:
object ImplicitTest{
case class Foo()
def myOtherFun()(implicit myfoo: Foo) = {
val grabImpFoo = implicitly[Foo]
println(myfoo.toString + " from myOtherFun")
}
}
import ImplicitTest._
class ImplicitTest {
def myFun()(implicit myfoo: Foo) = {
println(myfoo.toString)
myOtherFun()
}
}
Now run it:
implicit val foo = Foo()
val it = new ImplicitTest()
it.myFun()
This seems to demonstrate to me that implicit parameters are themselves implicit since myOtherFun
can find an implicit argument, which I did not believe was the case for some time! I suppose this has advantages and disadvantages, but I'm just here to learn the facts; I looked at http://docs.scala-lang.org/tutorials/FAQ/finding-implicits.html (based on Passing scala.math.Integral as implicit parameter) and didn't see any mention of this fact, if I'm understanding things correctly.