Я пытаюсь разрешить неявное, а затем использовать тип, сохраненный в нем, для разрешения второго неявного.
Вот код:
sealed trait ReturnTypeRetriever[T] {
type ReturnType
}
object ReturnTypeRetrievers {
implicit val expl = new ReturnTypeRetriever[ExplorationStreamFilter] {
type ReturnType = SimpleFilter[Context, Context]
}
}
sealed trait Retriever[T, +R] {
def get(config: Config): R //SimpleFilter[Context, Context]
}
object Retrievers {
// implementation here for T=ExplorationStreamFilter and R=SimpleFilter[Context, Context]
implicit val expl = new Retriever[ExplorationStreamFilter, SimpleFilter[Context, Context]] {
override def get(config: Config) = {..}
}
// putting it all together
def getOrEmpty[A](config: Config)(implicit evret: ReturnTypeRetriever[A]) = {
val ev = implicitly[Retriever[A, evret.ReturnType]] <-- ERROR 1: cannot find implicit defined above ^
ev.get(config)
}
}
Вызывая его так:
lazy val exploration = getOrEmpty[ExplorationStreamFilter](config) <--- ERROR 2: cannot find implicit here either
Компиляция показывает 2 ошибки:
ERROR 1 message: could not find implicit value for parameter e: Retriever[A,evret.ReturnType]
[error] val ev = implicitly[Retriever[A, evret.ReturnType]]
ERROR 2 message: could not find implicit value for parameter evret: ReturnTypeRetriever[ExplorationStreamFilter]
[error] lazy val exploration = getOrEmpty[ExplorationStreamFilter](config)
Почему компилятор не может найти неявное? Какое решение для этого?