-
-
Notifications
You must be signed in to change notification settings - Fork 14.2k
Closed
Description
I tried writing tarai function with Rust, version info is:
$ rustc --version
rustc 1.0.0-dev (3d5fbae33 2015-01-13 01:08:03 +0000)
written code is:
#![feature(unboxed_closures)]
fn tarai<F:Fn() -> i32>(x:i32, y:i32, z:F) -> i32 {
if x <= y {
y
}
else {
let fz = z();
let nx = tarai(x - 1, y, z);
let ny = tarai(y - 1, fz, |&:| { x });
let nz = |&:| { tarai(fz - 1, x, |&:| { y }) };
tarai(nx, ny, nz)
}
}
fn main() {
println!("{}", tarai(12, 6, |&:| { 0 }));
}but compiling this code, occurs an error like this:
$ rustc ./21-161505.rs
21-161505.rs:3:1: 15:2 error: reached the recursion limit during monomorphization
21-161505.rs:3 fn tarai<F:Fn() -> i32>(x:i32, y:i32, z:F) -> i32 {
21-161505.rs:4 if x <= y {
21-161505.rs:5 y
21-161505.rs:6 }
21-161505.rs:7 else {
21-161505.rs:8 let fz = z();
...
Why my code is wrong? And what should I do for pass compiling without errors?
Please show me these. Sorry for poor my english. Thank you.
Metadata
Metadata
Assignees
Labels
No labels