MoreLabels.Set.S(3)
π NAME β MoreLabels.Set.S(3) π
okay so MoreLabels.Set.S from the OCaml library is literally the output signature of the functor MoreLabels.Set.Make. That's the whole vibe, bestie β no cap.
π§ Module type π§
Module type MoreLabels.Set.S
β¨ Documentation β¨
Module type S
= sig end
Output signature of the functor MoreLabels.Set.Make.
π Sets π
type eltβ The type of the set elements.type tβ The type of sets.val empty : tβ The empty set.val add : elt -> t -> tβadd x sreturns a set containing all elements ofs, plusx. Ifxwas already ins,sis returned unchanged (the result of the function is then physically equal tos).
β οΈ Before 4.03, physical equality was not ensured.
val singleton : elt -> tβsingleton xreturns the one-element set containing onlyx.val remove : elt -> t -> tβremove x sreturns a set containing all elements ofs, exceptx. Ifxwas not ins,sis returned unchanged (the result of the function is then physically equal tos).
β οΈ Before 4.03, physical equality was not ensured.
val union : t -> t -> tβ Set union.val inter : t -> t -> tβ Set intersection.val disjoint : t -> t -> boolβ Test if two sets are disjoint. Since 4.08val diff : t -> t -> tβ Set difference:diff s1 s2contains the elements ofs1that are not ins2.val cardinal : t -> intβ Return the number of elements of a set.
π¦ Elements π¦
val elements : t -> elt listβ Return the list of all elements of the given set. The returned list is sorted in increasing order with respect to the orderingOrd.compare, whereOrdis the argument given toMoreLabels.Set.Make.val min_elt : t -> eltβ Return the smallest element of the given set (with respect to theOrd.compareordering), or raiseNot_foundif the set is empty.val min_elt_opt : t -> elt optionβ Return the smallest element of the given set (with respect to theOrd.compareordering), orNoneif the set is empty. Since 4.05val max_elt : t -> eltβ Same asMoreLabels.Set.S.min_elt, but returns the largest element of the given set.val max_elt_opt : t -> elt optionβ Same asMoreLabels.Set.S.min_elt_opt, but returns the largest element of the given set. Since 4.05val choose : t -> eltβ Return one element of the given set, or raiseNot_foundif the set is empty. Which element is chosen is unspecified, but equal elements will be chosen for equal sets.val choose_opt : t -> elt optionβ Return one element of the given set, orNoneif the set is empty. Which element is chosen is unspecified, but equal elements will be chosen for equal sets. Since 4.05
π Searching π
val find : elt -> t -> eltβfind x sreturns the element ofsequal tox(according toOrd.compare), or raiseNot_foundif no such element exists. Since 4.01val find_opt : elt -> t -> elt optionβfind_opt x sreturns the element ofsequal tox(according toOrd.compare), orNoneif no such element exists. Since 4.05val find_first : f:(elt -> bool) -> t -> eltβfind_first ~f s, wherefis a monotonically increasing function, returns the lowest elementeofssuch thatf e, or raisesNot_foundif no such element exists.
For example, find_first (fun e -> Ord.compare e x >= 0) s will return the first element e of s where Ord.compare e x >= 0 (intuitively: e >= x), or raise Not_found if x is greater than any element of s. Since 4.05
val find_first_opt : f:(elt -> bool) -> t -> elt optionβfind_first_opt ~f s, wherefis a monotonically increasing function, returns an option containing the lowest elementeofssuch thatf e, orNoneif no such element exists. Since 4.05val find_last : f:(elt -> bool) -> t -> eltβfind_last ~f s, wherefis a monotonically decreasing function, returns the highest elementeofssuch thatf e, or raisesNot_foundif no such element exists. Since 4.05val find_last_opt : f:(elt -> bool) -> t -> elt optionβfind_last_opt ~f s, wherefis a monotonically decreasing function, returns an option containing the highest elementeofssuch thatf e, orNoneif no such element exists. Since 4.05
π§ Traversing π§
val iter : f:(elt -> unit) -> t -> unitβiter ~f sappliesfin turn to all elements ofs. The elements ofsare presented tofin increasing order with respect to the ordering over the type of the elements.val fold : f:(elt -> 'acc -> 'acc) -> t -> init:'acc -> 'accβfold ~f s ~initcomputes(f xN ... (f x2 (f x1 init))...), wherex1...xNare the elements ofs, in increasing order.
π Transforming π
val map : f:(elt -> elt) -> t -> tβmap ~f sis the set whose elements aref a0,f a1...f aN, wherea0,a1...aNare the elements ofs.
The elements are passed to f in increasing order with respect to the ordering over the type of the elements.
If no element of s is changed by f, s is returned unchanged. (If each output of f is physically equal to its input, the returned set is physically equal to s.) Since 4.04
val filter : f:(elt -> bool) -> t -> tβfilter ~f sreturns the set of all elements insthat satisfy predicatef. If every element inssatisfiesf,sis returned unchanged (the result of the function is then physically equal tos).
β οΈ Before 4.03, physical equality was not ensured.
val filter_map : f:(elt -> elt option) -> t -> tβfilter_map ~f sreturns the set of allvsuch thatf x = Some vfor some elementxofs.
For example, filter_map (fun n -> if n mod 2 = 0 then Some (n / 2) else None) s is the set of halves of the even elements of s.
If no element of s is changed or dropped by f (if f x = Some x for each element x), then s is returned unchanged: the result of the function is then physically equal to s. Since 4.11
val partition : f:(elt -> bool) -> t -> t * tβpartition ~f sreturns a pair of sets(s1, s2), wheres1is the set of all the elements ofsthat satisfy the predicatef, ands2is the set of all the elements ofsthat do not satisfyf.val split : elt -> t -> t * bool * tβsplit x sreturns a triple(l, present, r), wherelis the set of elements ofsthat are strictly less thanx;ris the set of elements ofsthat are strictly greater thanx;presentisfalseifscontains no element equal tox, ortrueifscontains an element equal tox.
π Predicates and comparisons π
val is_empty : t -> boolβ Test whether a set is empty or not.val is_singleton : t -> boolβ Test whether a set has exactly one element or not. Since 5.5val mem : elt -> t -> boolβmem x stests whetherxbelongs to the sets.val equal : t -> t -> boolβequal s1 s2tests whether the setss1ands2are equal, that is, contain equal elements.val compare : t -> t -> intβ Total ordering between sets. Can be used as the ordering function for doing sets of sets.val subset : t -> t -> boolβsubset s1 s2tests whether the sets1is a subset of the sets2.val for_all : f:(elt -> bool) -> t -> boolβfor_all ~f schecks if all elements of the set satisfy the predicatef.val exists : f:(elt -> bool) -> t -> boolβexists ~f schecks if at least one element of the set satisfies the predicatef.
πΈ Converting πΈ
val to_list : t -> elt listβto_list sisMoreLabels.Set.S.elements s. Since 5.1val of_list : elt list -> tβof_list lcreates a set from a list of elements. This is usually more efficient than foldingaddover the list, except perhaps for lists with many duplicated elements. Since 4.02val to_seq_from : elt -> t -> elt Seq.tβto_seq_from x siterates on a subset of the elements ofsin ascending order, fromxor above. Since 4.07val to_seq : t -> elt Seq.tβ Iterate on the whole set, in ascending order. Since 4.07val to_rev_seq : t -> elt Seq.tβ Iterate on the whole set, in descending order. Since 4.12val add_seq : elt Seq.t -> t -> tβ Add the given elements to the set, in order. Since 4.07val of_seq : elt Seq.t -> tβ Build a set from the given elements. Since 4.07
π That's the whole page, bestie! This cutie was brought to you by OCamldoc, dated 2026-06-22, for manual page MoreLabels.Set.S(3). Periodt. π
π¦ where this page comes from
- arch rolling: ocaml 5.5.0-1 Β· LGPL2.1 AND custom: QPL-1.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms