In scala, what is A in the sum [B>: A] (implicit number: numeric [B]): B

I see this method in scala List.sum

sum[B >: A](implicit num: Numeric[B]): B

I now understand that he expects that any argument numwill be implicitly converted to Numeric[B], which means its value typeclass Numeric. However, I don’t understand what it is Aif it doesn’t reference it at all.

return value B and implementation

foldLeft(num.zero)(num.plus)

and numalso have a type Numeric[B], therefore, if the return value does not apply to A, and the implementation does not apply to A, why is this necessary?

+4
source share
1 answer

, A s. , B A, B >: A.

( , num.plus A fold.)

+6

Source: https://habr.com/ru/post/1536974/


All Articles