From: Denis B. <db...@gm...> - 2006-10-05 01:47:05
|
I've been building a compiler front-end (lex -> parse -> IR) in OCaml and frequently have to make use of List.iter2 --- and I find it annoying that there is no counterpart for arrays. Hasn't anyone needed this before? It's not hard to write. In fact, even better, it's written [1]. I'll spruce it up if it doesn't meet the ExtLib standards. -Denis [1] (** Like {!List.iter2}, but for arrays. @raise Invalid_argument if the length of [a1] does not equal the length of [a2]. *) let iter2 f a1 a2 = if Array.length a1 <> Array.length a2 then raise (Invalid_argument "Array.iter2"); for i = 0 to Array.length a1 do f a1.(i) a2.(i); done;; |