Jay Taylor's notesback to listing index
generics - scala 2.8 CanBuildFrom - Stack Overflow[web search]
Following on from another question I asked, I wanted to understand a bit more about the Scala method
Notice a few things about this method:
I can call this as follows:
What I cannot quite grasp is how the fact that
How is the scala compiler ensuring that
EDIT - this question of course boils down to: How does the compiler decide what implicit
Note that the second argument to
In your example,
There's no such thing in scope. Also,
Take a look, for instance, on the
Because it binds the second and third parameters through
So, how does one know where to look for, regarding such implicits? First of all, Scala does import a few things into all scopes. Right now, I can recall the following imports:
Since we are concerned about implicits, note that when you import things from packages, the only implicits possible are singletons. When you import things from objects (singletons), on the other hand, you can have implicit definitions, values and singletons.
Right now, there are
So, barring these automatic imports, and the explicit imports you make, where else can an implicit be found? One place: the companion objects of the instance on which the method is being applied.
I say companion object*s*, in the plural, because the companion objects of all traits and classes inherited by the class of the instance in question may contain relevant implicits. I'm not sure if the instance itself may contain an implicit. To be honest, I can't reproduce this right now, so I'm certainly making a mistake of some kind here.
At any rate, look inside the companion objects.