Hello,
I would like to pass a function as a parameter to a class constructor FuncY
. The class FuncY
then uses this function func
to perform some calculation.
class FuncY[A:Numeric](func: (A,A) => A, s1: A, s2: A) {
def current : A = func(s1,s2)
}
Now I would like to define a set of functions and use those to perform the calculations via FuncY
.
The next function is an example of what I want to use. Note that it has an implicit parameter
that will be used to operate on numeric values.
def sumFunc[A](a: A, b: A)(implicit num: Numeric[A]) : A = {
import num._
a + b
}
Finally I create specialized classes for the functions I need so:
case class Sum[A:Numeric](s1: A, s2: A) extends FuncY[A](sumFunc[A],s1,s2) {
override def current: A = sumFunc[A](s1, s2)
}
Unfortunately, I get a:
could not find implicit value for parameter num: Numeric[A]
[error] case class Sum[A:Numeric](s1: A, s2: A) extends FuncY[A](sumFunc[A],s1,s2) {
[error] ^
I have tried several variations of the above with no success. How can I do this?
TIA