Module Id
: sigend
Type identifiers.
A type identifier is a value that denotes a type. Given two type identifiers, they can be tested for
Type.Id.provably_equal to prove they denote the same type. Note that:
-Unequal identifiers do not imply unequal types: a given type can be denoted by more than one identifier.
-Type identifiers can be marshalled, but they get a new, distinct, identity on unmarshalling, so the
equalities are lost.
See an Type.Id.example of use.
Typeidentifierstype!'at
The type for identifiers for type 'a .
valmake : unit->'atmake() is a new type identifier.
valuid : 'at->intuidid is a runtime unique identifier for id .
valprovably_equal : 'at->'bt->('a,'b)Type.eqoptionprovably_equali0i1 is SomeEqual if identifier i0 is equal to i1 and None otherwise.
Example
The following shows how type identifiers can be used to implement a simple heterogeneous key-value
dictionary. In contrast to Map values whose keys map to a single, homogeneous type of values, this
dictionary can associate a different type of value to each key.
(**Heterogeneousdictionaries.*)moduleDict:sigtypet(**Thetypefordictionaries.*)type'akey(**Thetypeforkeysbindingvaluesoftype['a].*)valkey:unit->'akey(**[key()]isanewdictionarykey.*)valempty:t(**[empty]istheemptydictionary.*)valadd:'akey->'a->t->t(**[addkvd]is[d]with[k]boundto[v].*)valremove:'akey->t->t(**[removekd]is[d]withthelastbindingof[k]removed.*)valfind:'akey->t->'aoption(**[findkd]isthebindingof[k]in[d],ifany.*)end=structtype'akey='aType.Id.ttypebinding=B:'akey*'a->bindingtypet=(int*binding)listletkey()=Type.Id.make()letempty=[]letaddkvd=(Type.Id.uidk,B(k,v))::dletremovekd=List.remove_assoc(Type.Id.uidk)dletfind:typea.akey->t->aoption=funkd->matchList.assoc_opt(Type.Id.uidk)dwith|None->None|Some(B(k',v))->matchType.Id.provably_equalkk'with|SomeType.Equal->Somev|None->assertfalseend
OCamldoc 2025-06-12 Type.Id(3o)