Closed
Description
Can't compile:
enum Nil {Nil}
struct Cons<T> {head:int, tail:T}
trait Dot {fn dot(other:self) -> int;}
impl Nil:Dot {
fn dot(_:Nil) -> int {0}
}
impl<T:Dot> Cons<T>:Dot {
fn dot(other:Cons<T>) -> int {
self.head * other.head + self.tail.dot(other.tail)
}
}
fn test<T:Dot> (n:int, i:int, first:T, second:T) ->int {
match n {
0 => {first.dot(second)}
_ => {test (n-1, i+1, Cons {head:2*i+1, tail:first}, Cons{head:i*i, tail:second})}
}
}
fn main() {
let n = test(5, 0, Nil, Nil);
io::println(fmt!("%d", n));
}
Same code in Java, C# or Haskell works.