Uh oh!
There was an error while loading. Please reload this page.
Make AdditiveIterator and MultiplicativeIterator extensible - #23293
Conversation
rust-highfive
commented
Mar 11, 2015
r? @huonw (rust_highfive has picked a reviewer for you, use r? to override) |
huonw
commented
Mar 11, 2015
I suspect this change means that That said, there's deeper structure here: both of these consumers are operating on a monoid: an algebraic structure consisting an (associative) binary operator and an identity element for that operator. Other examples include appending strings/sequences/data structures in general. I idly wonder if approaching this concept from that more perspective may be better, instead of having two essentially identical traits. Thoughts, @aturon? |
aturon
commented
Mar 12, 2015
@tbu- I'm curious what coherence problems you were running into? I presume trying to add a blanket impl of some kind? We used to have something along the lines @huonw is suggesting, where these worked for types satisfying |
tbu-
commented
Mar 12, 2015
@aturon The problem is that |
tbu-
commented
Mar 30, 2015
@huonw Any updates on this one? |
SSheldon
commented
Mar 31, 2015
bors
commented
Apr 1, 2015
☔ The latest upstream changes (presumably #23936) made this pull request unmergeable. Please resolve the merge conflicts. |
SSheldon
commented
Apr 4, 2015
@tbu-, what do you think of moving these methods onto the |
huonw
commented
Apr 6, 2015
r? @aturon (transferring reviewership, don't have the bandwidth right now.) |
Previously it could not be implemented for types outside `libcore/iter.rs` due to coherence issues.
515c878 to
52bb3f7Comparetbu-
commented
Apr 6, 2015
@aturon I made |
aturon
commented
Apr 6, 2015
bors
commented
Apr 6, 2015
📌 Commit 52bb3f7 has been approved by |
There was a problem hiding this comment.
Could this also omit the T type parameter? I think something like this in theory shouldn't ICE:
fnsum<S=Self::Item>(self) -> SwhereS:Add<Self::Item,Output=S> + Zero,Self:Sized{
...}There was a problem hiding this comment.
@alexcrichton Indeed. Changing it right now.
alexcrichton
commented
Apr 6, 2015
Nice! |
52bb3f7 to
4b8a918CompareThere was a problem hiding this comment.
Does the output of Add need to be the same as the Item of the iterator? Could this be: fn sum(self) -> <Self::Item as Add>::Output where Self::Item: Add, Self::Item::Output: Zero
Not sure it's that worth it, but it'd allow summing when the output and input are different.
There was a problem hiding this comment.
The S=... part is just setting a default for the type parameter. Iterator type and type that is being summed over can be different in the code.
There was a problem hiding this comment.
But the Output=S part requires that the iterator's Item and the Output of Add be the same
There was a problem hiding this comment.
Ohhh I understand it now :) Disregard!
alexcrichton
commented
Apr 6, 2015
bors
commented
Apr 6, 2015
⌛ Testing commit 4b8a918 with merge 82d1a5e... |
bors
commented
Apr 6, 2015
💔 Test failed - auto-mac-32-opt |
In addition to being nicer, this also allows you to use `sum` and `product` for iterators yielding custom types aside from the standard integers. Due to removing the `AdditiveIterator` and `MultiplicativeIterator` trait, this is a breaking change. [breaking-change]
tbu-
commented
Apr 7, 2015
@alexcrichton Sorry for the inconvenience, |
4b8a918 to
97f24a8Comparealexcrichton
commented
Apr 8, 2015
Previously it could not be implemented for types outside `libcore/iter.rs` due to coherence issues.
bors
commented
Apr 8, 2015
⌛ Testing commit 97f24a8 with merge dd6c4a8... |
Previously it could not be implemented for types outside
libcore/iter.rsdueto coherence issues.