Skip to content

Instantly share code, notes, and snippets.

@jaguilar
Created May 22, 2013 01:12
Show Gist options
  • Save jaguilar/5624553 to your computer and use it in GitHub Desktop.
Save jaguilar/5624553 to your computer and use it in GitHub Desktop.
Things I don't understand about rust part 2
// 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