jon.recoil.org

Module Type_equal.IdSource

Id provides identifiers for types, and the ability to test (via Id.same) at runtime if two identifiers are equal, and if so to get a proof of equality of their types. Unlike values of type Type_equal.t, values of type Id.t do have semantic content and must have a nontrivial runtime representation.

Sourcetype ('a : any) t
include sig ... end
Sourceval sexp_of_t : ('a : any). (('a : any) -> Sexplib0.Sexp.t) -> ('a : any) Base.Type_equal.Id.t -> Sexplib0.Sexp.t
include sig ... end
module type Arg0 = sig ... end
module type S0 = sig ... end
module type Arg1 = sig ... end
module type S1 = sig ... end
module type Arg2 = sig ... end
module type Arg2__immediate64__value = sig ... end
module type S2 = sig ... end
module type S2__immediate64__value = sig ... end
module type Arg3 = sig ... end
module type S3 = sig ... end
module type Arg4 = sig ... end
module type S4 = sig ... end
Sourcemodule Uid : sig ... end

Every Id.t contains a unique id that is distinct from the Uid.t in any other Id.t.

Sourceval create : ('a : any). name:string -> ('a -> Sexplib0.Sexp.t) -> 'a Base.Type_equal.Id.t

create ~name defines a new type identity. Two calls to create will result in two distinct identifiers, even for the same arguments with the same type. If the type 'a doesn't support sexp conversion, then a good practice is to have the converter be [%sexp_of: _], (or sexp_of_opaque, if not using ppx_sexp_conv).

Accessors

Sourceval hash : ('a : any). 'a Base.Type_equal.Id.t -> int
Sourceval name : ('a : any). 'a Base.Type_equal.Id.t -> string
Sourceval to_sexp : ('a : any). 'a Base.Type_equal.Id.t -> 'a -> Sexplib0.Sexp.t

same_witness t1 t2 and same_witness_exn t1 t2 return a type equality proof iff the two identifiers are the same (i.e., physically equal, resulting from the same call to create). This is a useful way to achieve a sort of dynamic typing. same_witness does not allocate a Some every time it is called.

same t1 t2 = is_some (same_witness t1 t2).

Sourceval same_witness : ('a : any) ('b : any). 'a Base.Type_equal.Id.t -> 'b Base.Type_equal.Id.t -> ('a, 'b) Base.Type_equal.t option
Sourceval same_witness_exn : ('a : any) ('b : any). 'a Base.Type_equal.Id.t -> 'b Base.Type_equal.Id.t -> ('a, 'b) Base.Type_equal.t
Sourcemodule Create0 (T : sig ... end) : sig ... end
Sourcemodule Create1 (T : sig ... end) : sig ... end
Sourcemodule Create2 (T : sig ... end) : sig ... end
Sourcemodule Create3 (T : sig ... end) : sig ... end
Sourcemodule Create4 (T : sig ... end) : sig ... end