module Id:sig
..end
Id
provides identifiers for types, and the ability to test (via Id.same
) at
run-time 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.type 'a
t
module Uid:Unique_id_intf.Id
Id.t
contains a unique id that is distinct from the Uid.t
in any other
Id.t
.
val uid : 'a t -> Uid.t
val create : name:string -> 'a 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.val hash : 'a t -> int
val name : 'a t -> string
val same : 'a t -> 'b t -> bool
same_witness t1 t2
and same_witness_exn t1 t2
return a type equality proof iff
the two identifiers are physically equal. This is a useful way to achieve a sort of
dynamic typing.
The following two idioms are semantically equivalent; however, using same
and
same_witness_exn
instead of matching on same_witness
has better performance
because same_witness
would allocate an intermediate Or_error.t
.
match same_witness ta tb with
| None -> ...
| Some e -> ...
if not (same ta tb)
then ...
else
let e = same_witness_exn ta tb in
...
val same_witness : 'a t ->
'b t -> ('a, 'b) Type_equal.equal Or_error.t
val same_witness_exn : 'a t -> 'b t -> ('a, 'b) Type_equal.equal
val sexp_of_t : ('a -> Sexplib.Sexp.t) -> 'a t -> Sexplib.Sexp.t
Id.t
contains a unique id that is distinct from the Uid.t
in any other
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.same_witness t1 t2
and same_witness_exn t1 t2
return a type equality proof iff
the two identifiers are physically equal. This is a useful way to achieve a sort of
dynamic typing.
The following two idioms are semantically equivalent; however, using same
and
same_witness_exn
instead of matching on same_witness
has better performance
because same_witness
would allocate an intermediate Or_error.t
.
match same_witness ta tb with
| None -> ...
| Some e -> ...
if not (same ta tb)
then ...
else
let e = same_witness_exn ta tb in
...