Ajout de memq.
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@277 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02master
parent
3063276f8b
commit
960bc38a92
|
@ -95,6 +95,10 @@ let rec mem x = function
|
||||||
[] -> false
|
[] -> false
|
||||||
| a::l -> a = x or mem x l
|
| a::l -> a = x or mem x l
|
||||||
|
|
||||||
|
let rec memq x = function
|
||||||
|
[] -> false
|
||||||
|
| a::l -> a == x or mem x l
|
||||||
|
|
||||||
let rec assoc x = function
|
let rec assoc x = function
|
||||||
[] -> raise Not_found
|
[] -> raise Not_found
|
||||||
| (a,b)::l -> if a = x then b else assoc x l
|
| (a,b)::l -> if a = x then b else assoc x l
|
||||||
|
|
|
@ -83,6 +83,9 @@ val exists : ('a -> bool) -> 'a list -> bool
|
||||||
val mem : 'a -> 'a list -> bool
|
val mem : 'a -> 'a list -> bool
|
||||||
(* [mem a l] is true if and only if [a] is equal
|
(* [mem a l] is true if and only if [a] is equal
|
||||||
to an element of [l]. *)
|
to an element of [l]. *)
|
||||||
|
val memq : 'a -> 'a list -> bool
|
||||||
|
(* Same as [mem], but uses physical equality instead of structural
|
||||||
|
equality to compare list elements. *)
|
||||||
|
|
||||||
(** Association lists *)
|
(** Association lists *)
|
||||||
|
|
||||||
|
@ -97,7 +100,7 @@ val mem_assoc : 'a -> ('a * 'b) list -> bool
|
||||||
(* Same as [assoc], but simply return true if a binding exists,
|
(* Same as [assoc], but simply return true if a binding exists,
|
||||||
and false if no bindings exist for the given key. *)
|
and false if no bindings exist for the given key. *)
|
||||||
val assq : 'a -> ('a * 'b) list -> 'b
|
val assq : 'a -> ('a * 'b) list -> 'b
|
||||||
(* Same as [assoc], but use physical equality instead of structural
|
(* Same as [assoc], but uses physical equality instead of structural
|
||||||
equality to compare keys. *)
|
equality to compare keys. *)
|
||||||
|
|
||||||
(** Lists of pairs *)
|
(** Lists of pairs *)
|
||||||
|
|
Loading…
Reference in New Issue