123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100open!Importtype'at='a->unittype'ainv='atmoduletypeS=sigtypetvalinvariant:tinvendmoduletypeS1=sigtype'atvalinvariant:'ainv->'atinvendmoduletypeS2=sigtype('a,'b)tvalinvariant:'ainv->'binv->('a,'b)tinvendmoduletypeS3=sigtype('a,'b,'c)tvalinvariant:'ainv->'binv->'cinv->('a,'b,'c)tinvendmoduletypeInvariant=sig(** This module defines signatures that are to be included in other signatures to ensure
a consistent interface to invariant-style functions. There is a signature ([S],
[S1], [S2], [S3]) for each arity of type. Usage looks like:
{[
type t
include Invariant.S with type t := t
]}
or
{[
type 'a t
include Invariant.S1 with type 'a t := 'a t
]}
*)typenonrec'at='atmoduletypeS=SmoduletypeS1=S1moduletypeS2=S2moduletypeS3=S3(** [invariant here 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 [%here] t [%sexp_of: t] (fun () ->
... check t's invariants ... )
]}
For polymorphic types:
{[
let invariant check_a t =
Invariant.invariant [%here] t [%sexp_of: _ t] (fun () -> ... )
]}
It's okay to use [ [%sexp_of: _ t] ] because the exceptions raised by [check_a] will
show the parts that are opaque at top-level. *)valinvariant:Source_code_position0.t->'a->('a->Sexp.t)->(unit->unit)->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;
}
[@@deriving fields]
let invariant t : unit =
Invariant.invariant [%here] t [%sexp_of: t] (fun () ->
let check f = Invariant.check_field t f in
Fields.iter
~foo:(check Foo.invariant)
~bar:(check Bar.invariant))
;;
]} *)valcheck_field:'a->'bt->('a,'b)Field.t->unitend