2012-09-11 19:46:20 -05:00
|
|
|
extern mod std;
|
2011-12-15 20:44:13 -06:00
|
|
|
|
2012-09-05 14:32:05 -05:00
|
|
|
use comm::Chan;
|
|
|
|
use comm::send;
|
2011-12-15 20:44:13 -06:00
|
|
|
|
|
|
|
fn main() { test05(); }
|
|
|
|
|
|
|
|
type pair<A,B> = { a: A, b: B };
|
|
|
|
|
2012-09-07 16:52:28 -05:00
|
|
|
fn make_generic_record<A: Copy, B: Copy>(a: A, b: B) -> pair<A,B> {
|
2012-08-01 19:30:05 -05:00
|
|
|
return {a: a, b: b};
|
2011-12-15 20:44:13 -06:00
|
|
|
}
|
|
|
|
|
2012-07-14 00:57:48 -05:00
|
|
|
fn test05_start(&&f: fn~(&&float, &&~str) -> pair<float, ~str>) {
|
|
|
|
let p = f(22.22f, ~"Hi");
|
2011-12-22 19:53:53 -06:00
|
|
|
log(debug, p);
|
2011-12-15 20:44:13 -06:00
|
|
|
assert p.a == 22.22f;
|
2012-07-14 00:57:48 -05:00
|
|
|
assert p.b == ~"Hi";
|
2011-12-15 20:44:13 -06:00
|
|
|
|
2012-07-14 00:57:48 -05:00
|
|
|
let q = f(44.44f, ~"Ho");
|
2011-12-22 19:53:53 -06:00
|
|
|
log(debug, q);
|
2011-12-15 20:44:13 -06:00
|
|
|
assert q.a == 44.44f;
|
2012-07-14 00:57:48 -05:00
|
|
|
assert q.b == ~"Ho";
|
2011-12-15 20:44:13 -06:00
|
|
|
}
|
|
|
|
|
2012-09-07 16:52:28 -05:00
|
|
|
fn spawn<A: Copy, B: Copy>(f: extern fn(fn~(A,B)->pair<A,B>)) {
|
2012-01-11 11:58:05 -06:00
|
|
|
let arg = fn~(a: A, b: B) -> pair<A,B> {
|
2012-08-01 19:30:05 -05:00
|
|
|
return make_generic_record(a, b);
|
2011-12-15 20:44:13 -06:00
|
|
|
};
|
2012-06-30 18:19:07 -05:00
|
|
|
task::spawn(|| f(arg) );
|
2011-12-15 20:44:13 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
fn test05() {
|
2012-07-14 00:57:48 -05:00
|
|
|
spawn::<float,~str>(test05_start);
|
2011-12-15 20:44:13 -06:00
|
|
|
}
|