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)
You need a Numeric[GF2] implicit:
trait GF2IsNumeric extends Numeric[GF2] {
def plus(x: GF2, y: GF2): GF2 = x + y
def minus(x: GF2, y: GF2): GF2 = x + (-y)
def times(x: GF2, y: GF2): GF2 = x * y
def negate(x: GF2): GF2 = -x
def fromInt(x: Int): GF2 = ???
def toInt(x: GF2): Int = ???
def toLong(x: GF2): Long = ???
def toFloat(x: GF2): Float = ???
def toDouble(x: GF2): Double = ???
override def zero = Zero
override def one = One
}
trait GF2Ordering extends scala.math.Ordering[GF2] {
override def compare(a: GF2, b: GF2) = if (a == b) 0 else if (b == One) 1 else -1
}
implicit object GF2IsNumeric extends GF2IsNumeric with GF2Ordering
Then you can do:
println(List(One, One, Zero, One).sum)
// One