Module type Invariant_intf.Invariant

module type Invariant = sig .. end

include ??
module type S = Invariant_intf.S
module type S1 = Invariant_intf.S1
module type S2 = Invariant_intf.S2
module type S3 = Invariant_intf.S3
val invariant : string -> 'a -> ('a -> Sexplib.Sexp.t) -> (unit -> unit) -> unit
invariant name t sexp_of_t f runs f (), and if f raises, wraps the exception in an Error.t that states "invariant failed" and includes both the exception raised by f, as well as sexp_of_t t. Idiomatic usage looks like:

        invariant "Foo.invariant" t <:sexp_of< t >> (fun () ->
          ... check t's invariants ... )
      

val check_field : 'a -> 'b Invariant_intf.t -> ('a, 'b) Fieldslib.Field.t -> unit
check_field is used when checking invariants using Fields.iter. It wraps an exception raised when checking a field with the field's name. Idiomatic usage looks like:

        type t =
          { foo : Foo.t;
            bar : Bar.t;
          }
        with fields

        let invariant t : unit =
          invariant "Foo.invariant" t <:sexp_of< t >> (fun () ->
            let check f = Invariant.check_field t f in
            Fields.iter
              ~foo:(check Foo.invariant)
              ~bar:(check Bar.invariant))
        ;;