List.sum on custom class

后端 未结 3 550
日久生厌
日久生厌 2021-01-15 03:32

I have the following code that represents GF2 field:

trait GF2 {
  def unary_- = this
  def + (that: GF2): GF2
  def * (that: GF2): GF2

  def / (that: GF2)          


        
3条回答
  •  南方客
    南方客 (楼主)
    2021-01-15 04:18

    You need to implement a version of Numeric for your trait in order for it to work. See here for the full definition you'll need to create.

     object InScope{
       implicit object GF2Numeric extends Numeric[GF2]{
         //..your implementation here
       }
     }
    

    The full signature of sum on a List is actually:

     def sum(implicit num: Numeric[A])
    

    Where by the A is the type of the List[A].

提交回复
热议问题