title: Where does Scala look for implicits?
body: <p>An <em>implicit</em> question to newcomers to Scala seems to be: where does the compiler look for implicits? I mean implicit because the question never seems to get fully formed, as if there weren't words for it. :-) For example, where do the values for <code>integral</code> below come from?</p>
  
  <pre><code>scala&gt; import scala.math._
  import scala.math._
  
  scala&gt; def foo[T](t: T)(implicit integral: Integral[T]) {println(integral)}
  foo: [T](t: T)(implicit integral: scala.math.Integral[T])Unit
  
  scala&gt; foo(0)
  scala.math.Numeric$IntIsIntegral$@3dbea611
  
  scala&gt; foo(0L)
  scala.math.Numeric$LongIsIntegral$@48c610af
  </code></pre>
  
  <p>Another question that does follow up to those who decide to learn the answer to the first question is how does the compiler choose which implicit to use, in certain situations of apparent ambiguity (but that compile anyway)?</p>
  
  <p>For instance, <code>scala.Predef</code> defines two conversions from <code>String</code>: one to <code>WrappedString</code> and another to <code>StringOps</code>. Both classes, however, share a lot of methods, so why doesn't Scala complain about ambiguity when, say, calling <code>map</code>?</p>
  
  <p><strong>Note:</strong> this question was inspired by <a href="https://stackoverflow.com/questions/5512397/passing-scala-math-integral-as-implicit-parameter">this other question</a>, in the hopes of stating the problem in a more general manner. The example was copied from there, because it is referred to in the answer.</p>