-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Confusing behavior of Monoid[Xor[A, B]]#combine #888
Comments
It seems that two lefts combine, and two right combine, but a left and a right combined is a left. I think that is consistent with Scalaz, eg [https://gist.github.com/travisbrown/3732844]. It's an interpretation where a failure of a part fails the combined group. But I can definitely imagine cases where you'd want to opposite, to discard failures. Like a lot of types, there are several monoids for Xor and one gets blessed as the default. But IMO its a mistake to think of it as the monoid for Xor.
|
@notxcain sorry I missed this issue when you first opened it, but I was thinking the same thing the other day. I would expect the errors to combine for There was a conversation about this on Gitter yesterday. |
Resolves typelevel#888 I don't think there's really a _right_ answer here. Both methods of combining `Xor`s are straightforward and law-abiding. However, I think that since in pretty much every other context (including the `SemigroupK` instances), `Xor` does not combine failures and `Validated` does, it is less surprising behavior to not combine left values in `combine` methods for `Xor` and `XorT`. Some notes about related implementations: - Scalaz's respective methods (and semigroup instances) _do_ combine errors, so this is a deviation from that. - The `Semigroup` for `Either` in Haskell has doesn't combine values at all, but returns the first `Right` (if any), making it equivalent to the behavior of `orElse` and the `SemigroupK` instance for `Xor`. Since we have already decided to not go with `orElse`-like behavior for our `Option` semigroup, I'm inclined to not take this approach for `Xor`.
Resolves typelevel#888 I don't think there's really a _right_ answer here. Both methods of combining `Xor`s are straightforward and law-abiding. However, I think that since in pretty much every other context (including the `SemigroupK` instances), `Xor` does not combine failures and `Validated` does, it is less surprising behavior to not combine left values in `combine` methods for `Xor` and `XorT`. Some notes about related implementations: - Scalaz's respective methods (and semigroup instances) _do_ combine errors, so this is a deviation from that. - The `Semigroup` for `Either` in Haskell has doesn't combine values at all, but returns the first `Right` (if any), making it equivalent to the behavior of `orElse` and the `SemigroupK` instance for `Xor`. Since we have already decided to not go with `orElse`-like behavior for our `Option` semigroup, I'm inclined to not take this approach for `Xor`. See also typelevel#996 (comment)
Don’t you feel that it’s strange that
Monoid[Xor[A, B]]
requiresA: Semigroup
?I expected
combine
to be implemented like thisIn current implementation it also tries to combine
Left
sThe text was updated successfully, but these errors were encountered: