Iltotore/iron

Support MultiplicativeGroup, AdditiveSemigroup and friends

erikerlandson opened this issue · 8 comments

Describe the solution you'd like
For the purposes of coulomb I would integrate with iron using certain constraints, primarily restrictions that preserve algebraic behavior. An example is that positive numbers are a multiplicative group. MultiplicativeGroup[IronType[V, Positive]]

Describe alternatives you've considered
The alternative would be to provide them in coulomb myself, as I did for refined

Note: Before posting your issue, check if it doesn't exists in the latest version.

The particular algebras I defined for refined are here:
https://github.com/erikerlandson/coulomb/tree/v0.9.0-RC1/refined/src/main/scala/coulomb/integrations/refined/algebra

I would define the same algebras for iron. some of these might make sense to define directly in iron

Hello.

I read the refined version you sent and I'm not sure about AdditiveSemigroup. AFAIK, addition can give a negative number if it overflows.

scala> Int.MaxValue + 1
val res0: Int = -2147483648

but MultiplicativeGroup should be ok.

It is possible to underflow multiplication (it's one of my unit tests). Like machine epsilon * machine epsilon. It might be a problem for your library since IronType[V] <: V

This might also be a "non-issue" aswell. Maybe the overflow/underflow case is too marginal to justify not adding AdditiveSemiroup and others in cats module.

I don't think there is a right or wrong answer. My own philosophy is that the benefits of defining these algebras on native types outweighs the downside of overflows or underflows breaking lawfulness. If total soundness is important, then there is always BigDecimal, BigInt, spire Rational, etc. However, type soundness is a core value of Scala and I respect the school of thought that one should avoid types that can be subverted by even rare cases.

My own philosophy is that the benefits of defining these algebras on native types outweighs the downside of overflows or underflows breaking lawfulness. If total soundness is important, then there is always BigDecimal, BigInt, spire Rational, etc.

Looks legit to me and I actually did not think about BigDecimal/BigInt 👍

Does refined's Positive includes 0?

No, refined distinguishes between Positive and NonNegative