tixxit on master
Fix Polynomial Gen Merge pull request #758 from Lu… (compare)
import cats.Monoid
import cats.implicits._
import spire.math._
import spire.implicits._
import algebra.ring.AdditiveMonoid
implicit def additiveToMonoid[A: AdditiveMonoid]: Monoid[A] =
AdditiveMonoid[A].additive
val x = List(Rational(4) / 5, Rational(2) / 3).combineAll
println(x)
Rational
is just spire.math.Rational
AdditiveMonoid
should just be Monoid
😝
case class Multiplicative[A](a: A) extends AnyVal // or opaque type
implicit def multiplicativeMonoidSemiring[A: Semiring]: Monoid[Multiplicative[A]] = …
cats
derivations to combine Map (for example, when a Map represents a polynomial)
trait Semiring[A] extends CommutativeMonoid[A] {
def times[A](x: A, y: A): A
def plus[A](x: A, y: A): A = combine(x, y)
def zero[A] = empty[A]
}
trait Rig[A] extends Semiring[A] {
def one[A]: A
}
cats
instances yet, and we haven't taken a position on whether our instances/laws/... should be inherited through the chain cats-kernel/algebra/spire
Monoid[Rational]
in spire.optional
; however, I'm not clear about the default instances in spire, and reluctant to pile more stuff on top of it
Semiring
is defined there