Assuming the following setup:
trait A[L] { def op(l1:L, l2:L): L }
trait E[L] { def op(l:L): L }
implicit def some2E[L:A](self:L) = new E[L] { def op(other:L) =
implicitly[A[L]].op(self,other) }
Is there a way to directly expand m op n
to a.op(m,n)
, in a context where a
is the appropriate implicit A
, using macros or at least avoid the additional object creation?
If you move the implicit parameter to the
op
method, you can use a value class to prevent the additional object creation:Hotspot will probably inline the call to the
op
defined insome2E
, so you will end up witha.op(m, n)
.