RosettaCodeData/Task/Loop-over-multiple-arrays-simultaneously/OCaml/loop-over-multiple-arrays-simultaneously-2.ocaml

12 lines
344 B
Text
Raw Permalink Normal View History

2013-04-10 22:43:41 -07:00
let n_arrays_iter ~f = function
| [] -> ()
| x::xs as al ->
let len = Array.length x in
let b = List.for_all (fun a -> Array.length a = len) xs in
2015-11-18 06:14:39 +00:00
if not b then invalid_arg "n_arrays_iter: arrays of different
length";
2013-04-10 22:43:41 -07:00
for i = 0 to pred len do
let ai = List.map (fun a -> a.(i)) al in
f ai
done