2011-12-15 20:44:13 -06:00
|
|
|
use std;
|
|
|
|
|
2012-01-09 07:53:13 -06:00
|
|
|
import comm::chan;
|
|
|
|
import comm::send;
|
2011-12-15 20:44:13 -06:00
|
|
|
|
|
|
|
fn main() { test05(); }
|
|
|
|
|
|
|
|
type pair<A,B> = { a: A, b: B };
|
|
|
|
|
2012-01-05 08:35:37 -06:00
|
|
|
fn make_generic_record<A: copy, B: copy>(a: A, b: B) -> pair<A,B> {
|
2011-12-15 20:44:13 -06:00
|
|
|
ret {a: a, b: b};
|
|
|
|
}
|
|
|
|
|
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-07-03 18:11:00 -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> {
|
2011-12-15 20:44:13 -06:00
|
|
|
ret make_generic_record(a, b);
|
|
|
|
};
|
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
|
|
|
}
|