Take a look at the List module: http://caml.inria.fr/pub/docs/manual-ocaml/libref/List.html , specifically the exists method. Why you can just do this:
List.exists (fun x -> not x) [true;true;...;false;...]
The exists function will return true if any element in the list satisfies a predicate (function). In this case, the predicate is fun x -> not x , which will return true if x is false.
For general access to the list, you usually do this using pattern matching and recursion, or using the functions iter , map , fold_left and fold_right (among other things). Here's the implementation of exists using pattern matching:
let rec exists fl = match l with | [] -> false (* the list is empty, return false *) | h::t -> if (fh) then true (* the list has a head and a (possibly empty) tail. Check the return value of the predicate 'f' when applied to the head *) else exists ft (* the predicate is false, recursively call the `exists` function on the tail *)
edit: as Chuck sent, instead of fun x -> not x you can just use not .
Another possibility is to use the mem function:
List.mem false bools
source share