The upcoming compiler release is the occasion to batch breaking changes to the core libraries and for the occasion we’d like to unbias the Semigroup
instance for Map k a
.
This is a breaking change though because singleton k [a] <> singleton k [b]
currently evaluates to singleton k [a]
(the instance is left-biased, it prefers values from the left when there’s duplicate keys in both maps) but it would evaluate to singleton k [a, b]
instead should we unbias the instance (and require a Semigroup instance for the values).
There’s three reasons motivating this change:
-
The Semigroup instance for
Semigroup a => Object a
is already unbiased. We could bias this instance instead but I believe an unbiased instance to be more useful, especially with the appropriate combinators, see next points. As @garyb noted in https://github.com/purescript/purescript-ordered-collections/issues/36#issuecomment-733753621, an unbiased instance is also consistent with the instance forSemigroup a => Maybe a
. -
We can recover the behaviour of a left-biased instance with
First
or even a right-biased instance withLast
. The unbiased instance is more general and we can get wildly different behaviours by varying the underlying semigroup. -
Converting some
Map k a
toMap k (First a)
by mapping over all the values would be inefficient but we can safely coerce between those types now that we have Coercible. We can also greatly improve the ergonomics with a newtype and the combinators from Data.Newtype (see the issue).
There’s two ways to proceed if we decide to do this:
-
We can update the instance with the next compiler release. This means that some programs will silently change meaning, but at least this will be over in a single major release.
-
We can embark on a multi-year journey: deprecate the existing instance in 0.14, remove it in 0.15 and then add an unbiased instance in 0.16. This is safer but will take much longer.
That’s why we’re asking the community! Please vote to let us know what you would prefer.
- In favor of updating the instance in 0.14
- In favor of deprecating the instance first
- Neutral
- Against
0 voters