Stdlib.Type(3)
bestie, welcome to the Stdlib.Type(3) page from the OCaml library manual β itβs giving β¨ type-equality main character energy β¨ and weβre gonna get through it together, no cap π
β¨ NAME β¨
Stdlib.Type - no description
yep. thatβs literally the whole NAME section. iconic, honestly π
π Module π
Module Stdlib.Type
thatβs our module, bestie π«Ά
π Documentation π
Module Type : (module Stdlib__Type)
πΈ Type equality witness πΈ
type (_, _) eq =
| Equal : ('a, 'a) eq
okay so the whole point of eq is to represent type equalities that may not otherwise be known by the type checker (e.g. because they may depend on dynamic data). slay π
A value of type (a, b) eq represents the fact that types a and b are equal. literally the receipts for type equality π₯
If youβve got a value eq : (a, b) eq that proves types a and b are equal, you can use it to convert a value of type a to a value of type b by pattern matching on Equal:
let cast (type a) (type b) (Equal : (a, b) Type.eq) (a : a) : b = a
At runtime, this function simply returns its second argument unchanged. no extra drama, just vibes π
π¦ Type identifiers π¦
module Id : sig end
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. (yes, thatβs the actual wording π)
π thatβs the whole page, bestie β brought to you by OCamldoc, dated 2026-06-22, and filed under Stdlib.Type(3). slay responsibly β¨
π¦ where this page comes from
- arch rolling: ocaml 5.5.0-1 Β· LGPL2.1 AND custom: QPL-1.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms