Using implicit objects within classes
问题 I am trying to write code to represent polynomials within Scala. I need this code to be type polymorphic, so I am using implicits to deal with different types. I have: case class Mono[T](degree: Int, coeff: T) { def Degree: Int = return degree def Coeff: T = return coeff } class Poly[T](private val terms: List[Mono[T]]) { trait Semiring[T] { def add(x:T, y:T): T def mul(x:T, y:T): T def exponent(x: T, n:Int): T val unitA: T } implicit object IntSemiring extends Semiring[Int] { def add(x: Int,