Ajout de List.for_all2 et List.exists2.
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@299 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02master
parent
016f79071f
commit
36169b72a8
|
@ -91,6 +91,18 @@ let rec exists p = function
|
|||
[] -> false
|
||||
| a::l -> p a or exists p l
|
||||
|
||||
let rec for_all2 p l1 l2 =
|
||||
match (l1, l2) with
|
||||
([], []) -> true
|
||||
| (a1::l1, a2::l2) -> p a1 a2 & for_all2 p l1 l2
|
||||
| (_, _) -> invalid_arg "List.for_all2"
|
||||
|
||||
let rec exists2 p l1 l2 =
|
||||
match (l1, l2) with
|
||||
([], []) -> true
|
||||
| (a1::l1, a2::l2) -> p a1 a2 or exists2 p l1 l2
|
||||
| (_, _) -> invalid_arg "List.exists2"
|
||||
|
||||
let rec mem x = function
|
||||
[] -> false
|
||||
| a::l -> a = x or mem x l
|
||||
|
|
|
@ -77,9 +77,14 @@ val for_all : ('a -> bool) -> 'a list -> bool
|
|||
satisfy the predicate [p]. That is, it returns
|
||||
[(p a1) & (p a2) & ... & (p an)]. *)
|
||||
val exists : ('a -> bool) -> 'a list -> bool
|
||||
(* [exists p [a1; ...; an]] checks if at least one element of the list
|
||||
satisfies the predicate [p]. That is, it returns
|
||||
(* [exists p [a1; ...; an]] checks if at least one element of
|
||||
the list satisfies the predicate [p]. That is, it returns
|
||||
[(p a1) or (p a2) or ... or (p an)]. *)
|
||||
val for_all2 : ('a -> 'b -> bool) -> 'a list -> 'b list -> bool
|
||||
val exists2 : ('a -> 'b -> bool) -> 'a list -> 'b list -> bool
|
||||
(* Same as [for_all] and [exists], but for a two-argument predicate.
|
||||
Raise [Invalid_argument] if the two lists have
|
||||
different lengths. *)
|
||||
val mem : 'a -> 'a list -> bool
|
||||
(* [mem a l] is true if and only if [a] is equal
|
||||
to an element of [l]. *)
|
||||
|
|
Loading…
Reference in New Issue