Skip to content
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

Semigroup generic over Rhs #493

Merged
merged 1 commit into from
May 23, 2024
Merged

Conversation

antiguru
Copy link
Member

Adds support for implementing semigroup for types that can plus_equals
from another type, for example vectors and slices.

Fixes a bug where the semigroup implementation for Vec would add
overhanging elements twice, i.e., [1,2] + [1,1,1] would result in
[2,3,2] instead of [2,3,1].

This leaves one quirk where is_zero does not depend on Rhs, so Rust
cannot figure out which implementation to use when two are in scope,
forcing the caller to phrase it as <R as Semigroup>::is_zero(&value).
This only applies if R implements Semigroup + Semigroup<Other>.

Adds support for implementing semigroup for types that can plus_equals
from another type, for example vectors and slices.

Fixes a bug where the semigroup implementation for `Vec` would add
overhanging elements twice, i.e., `[1,2] + [1,1,1]` would result in
`[2,3,2`] instead of `[2,3,1]`.

This leaves one quirk where `is_zero` does not depend on `Rhs`, so Rust
cannot figure out which implementation to use when two are in scope,
forcing the caller to phrase it as `<R as Semigroup>::is_zero(&value)`.
This only applies if `R` implements `Semigroup + Semigroup<Other>`.

Signed-off-by: Moritz Hoffmann <[email protected]>
Copy link
Member

@frankmcsherry frankmcsherry left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good and oh my! Thanks for catching this.

@antiguru antiguru merged commit 9171e73 into TimelyDataflow:master May 23, 2024
7 checks passed
@antiguru antiguru deleted the semigroup_rhs branch May 23, 2024 13:48
This was referenced Oct 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants