package base

  1. Overview
  2. Docs
Legend:
Library
Module
Module type
Parameter
Class
Class type

Named allows the validation of subset and equality relationships between sets. A Named.t is a record of a set and a name, where the name is used in error messages, and Named.is_subset and Named.equal validate subset and equality relationships respectively.

The error message for, e.g.,

Named.is_subset { set = set1; name = "set1" } ~of_:{set = set2; name = "set2" }

looks like

        ("set1 is not a subset of set2" (invalid_elements (...elements of set1 - set2...)))

so name should be a noun phrase that doesn't sound awkward in the above error message. Even though it adds verbosity, choosing names that start with the phrase "the set of" often makes the error message sound more natural.

type ('a, 'cmp) set := ('a, 'cmp) t
type 'a t = {
  1. set : 'a;
  2. name : string;
}
val is_subset : ('a, 'cmp) set t -> of_:('a, 'cmp) set t -> unit Or_error.t

is_subset t1 ~of_:t2 returns Ok () if t1 is a subset of t2 and a human-readable error otherwise.

val equal : ('a, 'cmp) set t -> ('a, 'cmp) set t -> unit Or_error.t

equal t1 t2 returns Ok () if t1 is equal to t2 and a human-readable error otherwise.

OCaml

Innovation. Community. Security.