Off the top of my head, I'd take out the "&" in front of the "|x|" everywhere, it seems like you are borrowing a pointer out of something that is already a borrowed pointer to a function (expected &, found &&, you have one & too many, right? :-).
On Sun, Oct 27, 2013 at 2:15 PM, Ramakrishnan Muthukrishnan < vu3...@gmail.com> wrote: > I am having a hard time trying to figure out what is going on here. > > fn ntimes(f: &fn(int) -> int, n: int) -> &fn(int) -> int { > match n { > 0 => &|x| { x }, > _ => &|x| { f(x) }, > _ => &|x| > { > let nf = ntimes(f, n - 1); > nf(f(x)) > }, > } > } > > fn double(a: int) -> int { > a * 2 > } > > fn main() { > let quadruple = ntimes(double, 2); > println(format!("quad = {:d}", quadruple(2))); > } > > When I compile it, I get this error message: > > $ rustc --version > rustc 0.9-pre (950add4 2013-10-26 02:16:08 -0700) > host: x86_64-apple-darwin > > $ rustc fn1.rs > fn1.rs:2:4: 10:5 error: mismatched types: expected > `&fn<no-bounds>(int) -> int` but found `&&fn<no-bounds>(int) -> int` > (expected fn but found &-ptr) > fn1.rs:2 match n { > fn1.rs:3 0 => &|x| { x }, > fn1.rs:4 _ => &|x| { f(x) }, > fn1.rs:5 _ => &|x| > fn1.rs:6 { > fn1.rs:7 let nf = ntimes(f, n - 1); > ... > error: aborting due to previous error > task '<unnamed>' failed at 'explicit failure', > /Users/rkrishnan/src/rust/src/libsyntax/diagnostic.rs:101 > task '<unnamed>' failed at 'explicit failure', > /Users/rkrishnan/src/rust/src/librustc/rustc.rs:396 > > Can someone help me understand what is going on here? I tried omitting > the return type of ntimes and let compiler try to infer the type. The > only change is in the first line of the code omitting the return type > of ntimes. But I then get an error about quadruple function. It says > that quadruple is a void. > > Thanks. > -- > Ramakrishnan > _______________________________________________ > Rust-dev mailing list > Rust-dev@mozilla.org > https://mail.mozilla.org/listinfo/rust-dev >
_______________________________________________ Rust-dev mailing list Rust-dev@mozilla.org https://mail.mozilla.org/listinfo/rust-dev