title: How to override predefined function in Scala?
body: <p>I need to implement function <code>to</code>. I have the following working code:</p>
  
  <pre><code>object Main {
  
    val m = 0
    val km = 1
  
    implicit def wrapM(v: Int) = new {
      def m = v
    }
  
    implicit def wrapKm(v: Int) = new {
      def km = v * 1000
    }
  
    implicit class toWrap(fromVal: Int) {
      def too (value: Int): Double = {
        if (value.equals(km)) {
          fromVal / 1000.0
        } else {
          0
        }
      }
    }
  
    def main(args:Array[String])
    {
      println(53.m too km)
    }
  }
  </code></pre>
  
  <p>But there is one problem. I use <code>too</code> name, instead of <code>to</code>. If I rename it to <code>to</code>, then I get the error:</p>
  
  <pre><code>Error:(30, 16) type mismatch;
   found   : Int
   required: ?{def to(x$1: ? &gt;: Int): ?}
  Note that implicit conversions are not applicable because they are ambiguous:
   both method intWrapper in class LowPriorityImplicits of type (x: Int)scala.runtime.RichInt
   and method toWrap in object Main of type (fromVal: Int)Main.toWrap
   are possible conversion functions from Int to ?{def to(x$1: ? &gt;: Int): ?}
      println(53.m to km)
                 ^
  </code></pre>
  
  <p>It is due to the fact, that there is one other function <code>to</code> - <code>scala.runtime.RichInt#to</code>.</p>