Q:

Find implicit depending on implicit

I have an implicit value, that is depending on another implicit. I want to import the first implicit, when the second is in scope:
trait B
trait A

implicit def provideAnA(implicit b:B) = {
    implicit val a = new A{}
}

def myMeth(implicit a:A) = 42

{
    implicit val implB = new B{}
    // i would like to be able to pass this through compiler
    myMeth()    
}

Is this possible somehow?

A:

In your definition of provideAnA you create an implicit variable. This variable is not in scope of myMeth and is also unnecessary. Just return the value from provideAnA and it should work. So your provideAnA method should look like this:
implicit def provideAnA(implicit b:B) = new A{}

And also you have to remove the parentheses from the call to myMeth, because otherwise the compiler tries to call it without parameters and does not find an impl for that.

