scala - Implicit resolution from trait -
i have use case similar situation following:
trait { implicit val x = "hello" } class b { // somehow bring x scope here??? def run(x: int)(implicit y: string) = y + x } println((new b).run(3))
i understand need bring x
defined in trait in implicit scope of b. i've tried following:
# attempt 1 # class b extends { .... } /// doesn't work # attempt 2 # class b extends { val x1 = implicitly[string] /// doesn't work either def run(x: int)(implicit y: string) = y + x }
please explain missing here (or, point me relevant theory topic can study, new scala).
the value of 'implicit y' resolved in println-line not available. making variable implicitly available within body of class, resolution of implicit string not needed there.
implicit isn't magic; if can't reach implicit variable explicitly can't compiler.
what problem trying solve?
Comments
Post a Comment