1

scala の数学フレームワークである「spire」を使用しようとしましたが、予期しないエラーが発生しました。これが私の小さなプログラムです。

import spire.algebra._
import spire.implicits._

trait AbGroup[A] extends Group[A]

final class Rationnel_Quadratique(val n1: Int = 2)(val coef: (Int, Int)) {
override def toString = {
    coef match {
        case (c, i) =>
            s"$c + $i√$n"
    }
}

def a() = coef._1

def b() = coef._2

def n() = n1


}

object Rationnel_Quadratique {

def apply(coef: (Int, Int),n: Int = 2) {
    new Rationnel_Quadratique(n)(coef)
}


}

object AbGroup {

implicit object RQAbGroup extends AbGroup[Rationnel_Quadratique] {
    def +(a: Rationnel_Quadratique, b: Rationnel_Quadratique): Rationnel_Quadratique = Rationnel_Quadratique(coef=(a.a() + b.a(), a.b() + b.b()))   <---

    def inverse(a: Rationnel_Quadratique): Rationnel_Quadratique = Rationnel_Quadratique((-a.a(), -a.b()))

    def id: Int = Rationnel_Quadratique((0, 0))
}

}


object euler66_2 extends App {

println("salut")

val a = r"10/7"
val b = r"5/12"
println(a / b)

val c = Rationnel_Quadratique(1, 2)
val d = Rationnel_Quadratique(3, 4)
val e = c + d
println(e)


}

エラーは数学ではなく apply メソッドに依存しています: 矢印のある行では、コンパイラはタプルの使用を許可していません:

型の不一致; found : 必要な単位: Rationel_Quadratique def +(a: Rationnel_Quadratique, b: Rationel_Quadratique): Rationel_Quadratique = Rationnel_Quadratique(coef= ^

地図は使いたくないのですが、助けてもらえますか?

4

1 に答える 1