These are chat archives for non/algebra

14th
Mar 2018
Ryan Stull
@ryanstull
Mar 14 2018 03:31

Hello all,

Just curious, is there a reason the Additive and Multiplicative Typeclasses don't extend their general versions from Cats?

Here's the header of AdditiveSemiGroup:

package algebra
package ring

trait AdditiveSemigroup[@sp(Int, Long, Float, Double) A] extends Any with Serializable

So it doesn't actually extend Semigroup from Cats.

I'm running into a situation where I want to have a function defined for a cats.kernel.Semigroup but I can't pass an AdditiveSemigroup to it.

Currently I'm getting around this by using an implicit def to convert from the Additive and Multiplicative versions to the generic one. Is there a reason for this? or potentially a way to resolve it? Thanks

Denis Rosset
@denisrosset
Mar 14 2018 04:13
Yep, because some types have both additive and multiplicative semigroups defined, and if both extended cats.kernel.Semigroup that would lead to ambiguous implicits.
If my memory serves correctly, there is already a way to convert an AdditiveSemigroup to Semigroup by calling the method .additive; please check if it exists in algebra.
Ryan Stull
@ryanstull
Mar 14 2018 04:18
Ahhh, makes sense! Thanks a bunch!
jeremyrsmith
@jeremyrsmith
Mar 14 2018 08:26
inspired by @tpolecat’s diagrams of cats’ typeclass hierarchy (though not nearly as nice)
(it is pretty small on the gist preview, but if you right-click and open image in new tab it looks alright)
it’s an interesting question: what does it mean to be an additive or multiplicative group in the absence of the other (within a ring)
jeremyrsmith
@jeremyrsmith
Mar 14 2018 08:34
If a non-armchair mathematician has an answer I’d be fascinated to hear. I’m thinking something about multiplicative groups being combinatorial in nature, but it doesn’t seem like you can know that without “cheating” and looking at the structure of the group. Also I think there’s something there about relating a ring to a monad via multiply (eta) and add (mu). But as an armchair mathematician, I’ll leave it to the experts.
Luka Jacobowitz
@LukaJCB
Mar 14 2018 09:05
Awesome stuff @jeremyrsmith