RosettaCodeData/Task/Closures-Value-capture/OCaml/closures-value-capture.ocaml

8 lines
203 B
Text
Raw Permalink Normal View History

2015-02-20 09:02:09 -05:00
let () =
let cls = Array.init 10 (fun i -> (function () -> i * i)) in
Random.self_init ();
for i = 1 to 6 do
let x = Random.int 9 in
Printf.printf " fun.(%d) = %d\n" x (cls.(x) ());
done