fork download
  1. open Thread
  2. open Event
  3.  
  4. let rec map f = function [] -> []
  5. | x::xs -> f x::map f xs
  6.  
  7. let tmap' f l = let rec help = function [] -> []
  8. | x::xs -> let c = new_channel ()
  9. in let _ = Thread.create (fun c -> sync (send c (f x))) c
  10. in (receive c)::help xs
  11. in map sync (help l)
  12.  
  13. (*the above versus the one below*)
  14. let tmap f l =
  15. let res = List.map (fun a ->
  16. let c = new_channel () in
  17. let _ = create (fun c -> sync(send c (f a))) c in
  18. receive c) l in
  19. List.map sync res
  20.  
  21. let x = tmap (fun a -> delay 5.; a + a) [12;3;46;35];;
  22.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
File "prog.ml", line 1, characters 5-11:
Error: Unbound module Thread
stdout
Standard output is empty