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