I tried to write an average function, but so far failed to convince the type checker.
fn average<T:Int>(values:&[T]) -> T { let count = values.len(); let mut sum:T; for v in values.iter() { sum = sum.add(v); } return sum / count; } error: mismatched types: expected `T` but found `uint` (expected type parameter but found uint) The problem is that sum is the generic type T, but count is uint due to the definition of the len function. Casting "count as T" should work, i thought, but rustc seems to have another opinion? -- Andreas Zwinkau work email: zwin...@kit.edu private email: q...@web.de homepage: http://beza1e1.tuxen.de _______________________________________________ Rust-dev mailing list Rust-dev@mozilla.org https://mail.mozilla.org/listinfo/rust-dev