Can we pass and use a function that requires an implicit parameter?

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

I think that’s a bug with implicit resolution in calls to the super constructor, possibly related to this bug.

A workaround is to pass the implicit explicitly.

case class Sum[A](s1: A, s2: A)(implicit num: Numeric[A])
  extends FuncY[A](sumFunc[A](_,_)(num),s1,s2)

But that’s just hideous.

@Jasper-M

Thanks for the workaround - it may be hideous but it allows me to save on quite a bit of boilerplate code.
I see that you have added this examples to the bug report. I subscribed to that issue so that I know when I
can remove the explicit use of num.

Once again, thank you very much.