Type(3)

πŸŽ€ NAME πŸŽ€

Type β€” Type introspection. This is the Type(3) manual page from the OCaml library, and it’s lowkey all about looking at types from inside the code ✨.

πŸ“¦ Module πŸ’–

Module Type

πŸ’– Documentation πŸ’–

Module Type
 : sig end

Type introspection.

Since 5.1 🌱

πŸ¦‹ Type equality witness πŸ¦‹

type (_, _) eq =
 | Equal : ('a, 'a) eq

The purpose 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). not me explaining type lore 😭

A value of type (a, b) eq represents the fact that types a and b are equal. Slay.

If one has a value eq : (a, b) eq that proves types a and b are equal, one 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 cap β€” it’s literally just vibes and a cast ✨.

🧚 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. πŸ’…


okay that’s the whole page, bestie πŸ’– β€” source OCamldoc, date 2026-06-22, and it’s the Type(3) manual, periodt πŸŽ€

πŸ“¦ where this page comes from