In scala, it is not possible to require that an implicit conversion exist for the attribute parameter type. There is a good reason for this. Suppose we defined a as:
trait ATrait[T <% Int] { def method(v: T) { println(v: Int) } }
And then he made copies of it in two places:
package place1 { implicit def strToInt(s: String) = 5 val inst = new ATrait[String] } package place2 { implicit def strToInt(s: String) = 6 val inst = new ATrait[String] }
And then they used these instances, for example:
val a = if (someTest) place1 else place2 a.method("Hello")
Should print 5 or 6 ? That is, what implicit conversion should be used? Implicits must be found at compile time, but you donβt know what kind of implicit conversion the object was present.
In other words, implications are provided by the area in which they are used, and not by the objects in which they are used; the latter would be impossible.
So, about your problem. Instead of using implicit, you can use regular Member:
trait Summable[T] { def -= (v: T): Unit def -= (v: Int) { this -= (encode(v)) } def encode(i: Int): T } class Int4 (var x: Int, var y: Int, var z: Int, var w: Int) extends Summable[Int4] { def -= (v : Int4) : Unit = { x -= vx; y -= vy; z -= vz; w -= vw } def encode(i: Int) = Int4.int2Int4(i) }
Now the decrement method compiles correctly.
Another way of saying this, do not think about implications, since properties belonging to the type (ie, "can be implicitly converted from Int" are not INT4 properties). These are values ββthat can be identified using types.
Hope this helps.