I have the following piece of Scala with ambigiuous implicits, which I would have thought should work, due to lower priority given to inherited implicits. But it does not - it fails with an ambiguous implicit values
-error. Can someone explain to me why priorities does not work here?
trait Printer[-T] {
def prettify(instance:T): String
}
trait LowPriorityPrinter {
implicit val anyPrinter:Printer[Any] = new Printer[Any]{ def prettify(instance:Any) = instance.toString() }
}
object Printer extends LowPriorityPrinter {
implicit val intPrinter = new Printer[Int]{ def prettify(instance:Int) = instance.toString() }
}
object MyApp extends App {
def prettyprint[T](i:T)(implicit p:Printer[T]) = println(p.prettify(i))
prettyprint(234)
}