简体   繁体   中英

Scala, Type could not find implicit value for parameter n

import Numeric._
import grizzled.math.stats._

val l = List[Double](123.0, 133.0, 155.0, 166.0, 177.0)
println(median(l))

Above you see an example which describes the usage of the package grizzled.math.stats at scala grizzled doc . I am not able to reproduce this simple example.

I always get following errors:

  • could not find implicit value for parameter n: Numeric[Array[Double]]
  • not enough arguments for method median: (implicit n: Numeric[Array[Double]])Double. Unspecified value parameter n.

Any suggestion to resolve this compilation error is welcome. Thank you in advance.

median expects a var-arg argument. You could expand the list with _* syntax, like this:

import Numeric._
import grizzled.math.stats._

val l = List[Double](123.0, 133.0, 155.0, 166.0, 177.0)
println(median(l: _*))

This compiles and outputs 155.0.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM