Created
May 22, 2013 01:12
-
-
Save jaguilar/5624553 to your computer and use it in GitHub Desktop.
Things I don't understand about rust part 2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Why does this work . . . | |
trait Additive: Add<Self, Self> {} | |
fn sum<T, U: Zero + Additive>(seq: &[T], f: &fn(&T) -> U) -> U { | |
let mut u: U = Zero::zero(); | |
for seq.each |x| { u += f(x); }; | |
u | |
} | |
// . . . but this doesn't? | |
fn sum<T, U: Zero + Add<Self, Self>>(seq: &[T], f: &fn(&T) -> U) -> U { | |
let mut u: U = Zero::zero(); | |
for seq.each |x| { u += f(x); }; | |
u | |
} | |
// Callsite: | |
let mu = do sum(p) |x| { x.mu }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment