Why isn’t the implicit not found, even in something as trivial as:
class Wrapper[+A](data: Vector[A]) {
def sum[B >: A](implicit num: Numeric[B]) = data.sum
}
won’t compile, without resorting to manually passing in num to data.sum
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
§7.2 of Scala specification (page 107) states that
implicit parameters are inferred after any type arguments are inferred. I believe this is the problem.Typer infers most specific parameter for
data.sum–A, and then looks for implicitNumeric[A]in scope. He can’t substitute it withNumeric[B]becauseNumericis invariant.