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

8 lines
203 B
OCaml
Raw Permalink Normal View History

2023-07-01 11:58:00 -04: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