I have function:
def listSum[T](xs :List[T])(implicit abc : Numeric[T]): T = {
xs.sum
}
val IntList: List[Int] = List (1, 2, 3, 4)
val DList: List[Double] = List (1.0, 2.0, 3, 4)
the code example above works fine, but when I change to the function below it stops working with error
could not find implicit value for parameter
abc: Numeric[AnyVal]
Since AnyVal
is the base type I can do the addition, can't I ?
where are all the implicits defined?
def listSum(xs :List[AnyVal])(implicit abc : Numeric[AnyVal]) = {
xs.sum
}
val AList: List[AnyVal] = List (1, 2, 3, 4)
Also this is not working , I think for the same reason .
def listSum[T](xs :List[T])(implicit abc : Numeric[T]): T = {
xs.sum
}
val BList : List[Boolean] = List(true, false)
println(listSum(BList))