summaryrefslogtreecommitdiff
path: root/src/Collections.ml
diff options
context:
space:
mode:
authorSon Ho2022-10-20 21:11:57 +0200
committerSon Ho2022-10-20 21:11:57 +0200
commitaa0b10a24b8e6b8323b0741e8573ba4fc6283409 (patch)
treea6d37eea3cf1d9f10711f6119ebc54f6832890f9 /src/Collections.ml
parent5e1e4f11dc2f75f20728ea1022b29a67c87bc07c (diff)
Fix the semantics of drop
Diffstat (limited to 'src/Collections.ml')
-rw-r--r--src/Collections.ml14
1 files changed, 14 insertions, 0 deletions
diff --git a/src/Collections.ml b/src/Collections.ml
index 2cb298a7..351b6523 100644
--- a/src/Collections.ml
+++ b/src/Collections.ml
@@ -184,6 +184,7 @@ module type Set = sig
val pp : Format.formatter -> t -> unit
val show : t -> string
+ val pairwise_distinct : elt list -> bool
end
module MakeSet (Ord : OrderedType) : Set with type elt = Ord.t = struct
@@ -218,6 +219,19 @@ module MakeSet (Ord : OrderedType) : Set with type elt = Ord.t = struct
pp_string "}"
let show s = to_string None s
+
+ let pairwise_distinct ls =
+ let s = ref empty in
+ let rec check ls =
+ match ls with
+ | [] -> true
+ | x :: ls' ->
+ if mem x !s then false
+ else (
+ s := add x !s;
+ check ls')
+ in
+ check ls
end
(** A map where the bindings are injective (i.e., if two keys are distinct,