This commit is contained in:
Tim Chevalier 2012-11-01 15:14:36 -07:00
parent b269ac13cd
commit 768247f393
4 changed files with 48 additions and 0 deletions

View File

@ -0,0 +1,8 @@
type t<T> = { f: fn() -> T };
fn f<T>(_x: t<T>) {}
fn main() {
let x: t<()> = { f: { || () } };
f(x); //~ ERROR copying a noncopyable value
}

View File

@ -0,0 +1,13 @@
type boxedFn = { theFn: fn () -> uint };
fn createClosure (closedUint: uint) -> boxedFn {
{ theFn: fn@ () -> uint { closedUint } }
}
fn main () {
let aFn: boxedFn = createClosure(10);
let myInt: uint = aFn.theFn();
assert myInt == 10;
}

View File

@ -0,0 +1,10 @@
fn add(n: int) -> fn@(int) -> int {
fn@(m: int) -> int { m + n }
}
fn main()
{
assert add(3)(4) == 7;
let add3 : fn(int)->int = add(3);
assert add3(4) == 7;
}

View File

@ -0,0 +1,17 @@
fn add(n: int) -> fn@(int) -> int {
fn@(m: int) -> int { m + n }
}
fn main()
{
assert add(3)(4) == 7;
let add1 : fn@(int)->int = add(1);
assert add1(6) == 7;
let add2 : &(fn@(int)->int) = &add(2);
assert (*add2)(5) == 7;
let add3 : fn(int)->int = add(3);
assert add3(4) == 7;
}