score:2

Accepted answer

i think the answer is, you can't

class testimplicits[t] {
  def sayfoo(t: t)(implicit ev: foo[t]) = ev.foo(t)
  def sayfooindirect(t: t) = sayfoo(t)
}

sayfoo takes a parameter ev, that must be provided when you are calling it, explicitly or implicitly.

in body of sayfooindirect no implicit object of type foo[t] is available. to make it available, either pass it implicitly everywhere or use some other way to put it in scope. as your class is fixed with type t, you could take implicit foo[t] in constructor.

class testimplicits[t](implicit ev: foo[t]) {
  def sayfoo(t: t) = ev.foo(t)
  def sayfooindirect(t: t) = sayfoo(t)
}

using this approach following will work:

val b = new bar("test")
val t = new testimplicits[bar]
t.sayfooindirect(b)

Related Query

More Query from same tag