This repository was archived by the owner on Feb 8, 2022. It is now read-only.
This repository was archived by the owner on Feb 8, 2022. It is now read-only.
Integrating cats.kernel.Semigroup and friends #218
Open
Description
Right now, there's AdditiveSemigroup
and MultiplicativeSemigroup
which are then combined into Semiring
. This is all well and good, but unfortunately there's a huge amount of code out there written on the basis of cats.kernel.Semigroup
and it's a bit of a shame we can't reuse those.
Especially in Spire where the various numeric types don't have Monoid
instances and therefore can't be foldMap
ed.
Since in the Cats ecosystem numeric types usually come with an Additive Monoid as default, I would personally love to see that convention being expanded in this project, but I also understand there are some good reasons not to do that.
Here is some code I came up with that demonstrates how I'd personally like to have it:
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
}
Metadata
Metadata
Assignees
Labels
No labels