Array.for_all usage


Hi. I am trying to create a function which checks if all elements are false in an Array in the following way:

let iftrue = fun array ->
if Array.for_all (fun x -> x = true) array then true
else false;;

But I am getting an error Unbound value Array.for_all. Why is this


I just try this :

let if_false = Array.for_all (not) ;;

And it works perfectly.
Are you sure that your version of OCaml is at least 4.03.0?

val for_all : ('a -> bool) -> 'a array -> bool

Since 4.03.0

If you cannot upgrade your OCaml’s version, for_all could easily written :

let for_all f = Array.fold_left (fun acc x -> acc && (f x)) true