I'm trying to create a generic class with a generic type that is a subclass of Numeric (to make sure I'm dealing with numbers). and I tried " class NuVector[T<:Numeric[T]) " as a def class, and it compiles a fine.
Now I want to add PartiallyOrdered[T] to it. so I did the following:
class NuVector[T<:Numeric[T]) extends PartiallyOrdered[T] { val v = new Array [T] (_length) private val range = 0 to _length - 1 def compare(x:T,y:T)(implicit res:Numeric[T]) :Int= { res.compare(x,y) } def tryCompareTo [B >: NuVector [T]] (b: B) (implicit view$1: (B) => PartiallyOrdered [B]): Option [Int] = { compare(x,y) } implicit def castT2Ordering(x:T):Numeric[T]=x.asInstanceOf[Numeric[T]] implicit def castB2NuVector [B>:NuVector[T]] (b:B): NuVector[T]= { b.asInstanceOf[NuVector[T]] } }
It does not compile. The error I get when compiling:
could not find implicit value for parameter res:Numeric[T]
The scala version I'm using is 2.8
Any help is appreciated.
Thanks,
~ Tiger.
I do not know if this is a mistake or its problem with my definition.
generics scala
user166037
source share