My immediate thought of a use-case for this is dependency injection - DI containers are often used to simulate a dynamic environment, and the fundamental problem with using implicits for DI is that implicits are static. An example is having 2 different containers passed into a constructor at the same static call site, chosen depending on some runtime state.
On Wed, May 30, 2012 at 1:03 PM, Daniel Sobral wrote:> I hope I managed to provide some motivation for the proposed feature.Actually, that's the thing I failed to see in the whole text: a use
case. You talked about selecting an authentication method, which has
absolutely no need for the mechanism you mentioned, since the static
implicits are enough:
def auth(user: String)(implicit authenticator: Authenticator): Boolean = ???
abstract class Authenticator { def authenticate(user: String): Boolean }
object Authenticator {
implicit def getAuthenticator: Authenticator = /* check available
mechanisms and return one */ ???
}
In fact, I fail to see how dynamic implicits could help you here: if
more than one authentication is found, it would simply fail. You'd
need some code to check which of the declared ones is actually
available, then chose or compose them. None of that is part of
implicit resolution.
Now, I'm not just dismissing the whole notion, but I think it's a
solution looking for a problem. I'd rather see more and better
examples.
The notion you're discussing (namely, resolveAndInvoke) can be
realized in 2.10 with runtime compilation via toolboxes. Even
2.10.0-M3 is powerful enough to implement it.
The huge downside would be speed. Currently runtime compilation costs
a lot, and I can't immediately see how to trivialize this overhead.
Would be great to see some progress in the area of runtime
compilation, though. It's tantalizing to have a reflection framework
unified across stages and not being able to use it in unified manner
due to implementation details.
I've been doing something like this for about a year.
In my case, a base object has 7 mixins, Each
mixin has from 3 to 8 variants making a total
of 108864 possible mixins combinations for a base object.
Not only does it make no sense to actually generate
code for each possible combination, having 108864 such
classes, I imagine is a significant overhead - with or
without macro support.
So, after the most general base object is created, which
variants of each mixin is determine to best optimize
performance/memory/etc. and, using the BIC (Build-In-Compiler),
I generate that particular version and copy the general
object's data into the particularized version.
(Actually, I create a builder for that version which is
stored in a cache so it can be reused if that combination
of mixin variants is required again - which is very
often the case.
Also, Note that a base object lives as long as the application
is running and the application is an enterprise level app
and expected to run for weeks, months or more.)
Richard
On Wednesday, May 30, 2012 5:16:00 PM UTC+2, Eugene Burmako wrote:The notion you're discussing (namely, resolveAndInvoke) can be
realized in 2.10 with runtime compilation via toolboxes. Even
2.10.0-M3 is powerful enough to implement it.Interesting. I'll look into it.