You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This isn't cool, but I'm also not sure it's a major emergency, or even that it needs to be fixed, for a few reasons:
The current behavior is the same as the standard library's and will be expected by many users. Changing it to enforce commutativity is likely to break at least some users' expectations.
Java's BigDecimal (which Scala's BigDecimal wraps) doesn't have a MathContext attached to instances at all, and many users of Scala's BigDecimal use it in that way.
Our Eq instances for BigDecimal don't compare MathContext, so with respect to Cats's idea of equality for BigDecimals the instance actually is commutative.
@johnynek has argued in #3303 that we should do one of two things:
Define an ordering on MathContext and use that (probably via the max) in our implicit CommutativeGroup for BigDecimal.
Remove the implicit CommutativeGroup instance (possibly leaving an implicit Group with no commutativity guarantee, I guess?) and provide a method that takes a MathContext and returns a CommutativeGroup[BigDecimal].
If we do this we should probably also change our Eq instance for BigDecimal to make it compare the MathContexts (at least in our tests).
My vote is not to do anything, since that's the least likely to surprise users and doesn't seem terribly inconsistent to me, but I wanted to make sure all the options are on the table.
The text was updated successfully, but these errors were encountered:
…but only since you can observe the
MathContext
it carries along with it:This isn't cool, but I'm also not sure it's a major emergency, or even that it needs to be fixed, for a few reasons:
BigDecimal
(which Scala'sBigDecimal
wraps) doesn't have aMathContext
attached to instances at all, and many users of Scala'sBigDecimal
use it in that way.Eq
instances forBigDecimal
don't compareMathContext
, so with respect to Cats's idea of equality forBigDecimal
s the instance actually is commutative.@johnynek has argued in #3303 that we should do one of two things:
MathContext
and use that (probably via the max) in our implicitCommutativeGroup
forBigDecimal
.CommutativeGroup
instance (possibly leaving an implicitGroup
with no commutativity guarantee, I guess?) and provide a method that takes aMathContext
and returns aCommutativeGroup[BigDecimal]
.If we do this we should probably also change our
Eq
instance forBigDecimal
to make it compare theMathContext
s (at least in our tests).My vote is not to do anything, since that's the least likely to surprise users and doesn't seem terribly inconsistent to me, but I wanted to make sure all the options are on the table.
The text was updated successfully, but these errors were encountered: