let rec map f = function [] -> []
| x::xs -> f x::map f xs
let tmap' f l = let rec help = function [] -> []
| x::xs -> let c = new_channel ()
in let _
= Thread.create
(fun c
-> sync
(send c
(f x
))) c
in (receive c)::help xs
in map sync (help l)
(*the above versus the one below*)
let tmap f l =
let res
= List.map
(fun a
-> let c = new_channel () in
let _ = create (fun c -> sync(send c (f a))) c in
receive c) l in
let x = tmap (fun a -> delay 5.; a + a) [12;3;46;35];;
b3BlbiBUaHJlYWQKb3BlbiBFdmVudAoKbGV0IHJlYyBtYXAgZiA9IGZ1bmN0aW9uIFtdIC0+IFtdCiAgICAgICAgfCB4Ojp4cyAtPiBmIHg6Om1hcCBmIHhzCgpsZXQgdG1hcCcgZiBsID0gbGV0IHJlYyBoZWxwID0gZnVuY3Rpb24gW10gLT4gW10KICAgICAgICB8IHg6OnhzIC0+IGxldCBjID0gbmV3X2NoYW5uZWwgKCkKICAgICAgICAgIGluIGxldCBfID0gVGhyZWFkLmNyZWF0ZSAoZnVuIGMgLT4gc3luYyAoc2VuZCBjIChmIHgpKSkgYyAKICAgICAgICAgIGluIChyZWNlaXZlIGMpOjpoZWxwIHhzCiAgICAgICAgaW4gbWFwIHN5bmMgKGhlbHAgbCkKICAgICAgICAKKCp0aGUgYWJvdmUgdmVyc3VzIHRoZSBvbmUgYmVsb3cqKQpsZXQgdG1hcCBmIGwgPSAKCWxldCByZXMgPSBMaXN0Lm1hcCAoZnVuIGEgLT4gCgkJbGV0IGMgPSBuZXdfY2hhbm5lbCAoKSBpbiAKCQlsZXQgXyA9IGNyZWF0ZSAoZnVuIGMgLT4gc3luYyhzZW5kIGMgKGYgYSkpKSBjIGluIAoJCXJlY2VpdmUgYykgbCBpbgoJCUxpc3QubWFwIHN5bmMgcmVzCgkJCmxldCB4ID0gdG1hcCAoZnVuIGEgLT4gZGVsYXkgNS47IGEgKyBhKSBbMTI7Mzs0NjszNV07Owo=