Stdlib.Repr(3)

πŸŽ€ Stdlib.Repr πŸŽ€

okay bestie, so this one lives in the section 3 of the OCaml library manual β€” yes that's the manual name, we're folding it in like a lil name tag πŸ’– β€” and it's literally the page for Stdlib.Repr, which is the module that holds all your comparison goodies. No cap.


🌸 NAME 🌸

Stdlib.Repr β€” no description 🫠

like... that's it. that's the description. the manpage said "no description" and honestly? iconic minimalism.


πŸ¦‹ Module πŸ¦‹

Module Stdlib.Repr ✨


πŸ’œ DOCUMENTATION πŸ’œ

Module Repr : (module Stdlib__Repr)

so the docs are about the module named Repr, which is literally the same thing as (module Stdlib__Repr) β€” same energy, different outfit πŸ’…


πŸ’… Physical comparison πŸ’…

val phys_equal : 'a -> 'a -> bool

okay so phys_equal e1 e2 is the vibe check for physical equality of e1 and e2. 🫢

on mutable types β€” think references, arrays, byte sequences, records with mutable fields, and objects with mutable instance variables β€” phys_equal e1 e2 is true if and only if physically modifying e1 also affects e2. like, same actual object in memory. same main character, no copies, periodt. πŸ‘‘

on non-mutable types, the behavior of phys_equal is implementation-dependent β€” so don't come for me if it's weird, it's literally allowed to be πŸ™ˆ β€” however!! it is guaranteed that phys_equal e1 e2 implies compare e1 e2 = 0. so if you get true, the compare is gonna say they're equal, fr fr. ⭐


🌈 Polymorphic comparison 🌈

val equal : 'a -> 'a -> bool

equal e1 e2 tests for structural equality of e1 and e2 πŸ’–. mutable structures (e.g. references and arrays) are equal if and only if their current contents are structurally equal β€” even if the two mutable objects are not the same physical object. like, twins, not the same person. πŸ“

⚠️ equality between functional values raises Invalid_argument β€” functions don't do that. and equality between cyclic data structures may not terminate β€” it'll just sit there spinning forever like a group chat with no resolution πŸ˜­πŸ’€
val compare : 'a -> 'a -> int

compare x y returns 0 if x is equal to y, a negative integer if x is less than y, and a positive integer if x is greater than y. ✨

the ordering implemented by compare is compatible with the comparison predicates (=), (<) and (>), as well as the equal function defined above β€” with one difference on the treatment of the float value nan. πŸ‘€ namely:

  • the comparison predicates treat nan as different from any other float value, including itself
  • while compare treats nan as equal to itself and less than any other float value

this treatment of nan ensures that compare defines a total ordering relation πŸ† β€” no gaps, no drama, everyone has a seat at the table.

⚠️ compare applied to functional values may raise Invalid_argument. compare applied to cyclic structures may not terminate. same warning as before, it's giving consequences πŸ’€

the compare function can be used as the comparison function required by the Set.Make and Map.Make functors, as well as the List.sort and Array.sort functions. 🫢 plug it in anywhere, it's that versatile bestie.


val min : 'a -> 'a -> 'a

return the smaller of the two arguments πŸ’œ

⚠️ the result is unspecified if one of the arguments contains the float value nan. so like, don't. πŸ™ˆ

val max : 'a -> 'a -> 'a

return the greater of the two arguments πŸ‘‘

⚠️ the result is unspecified if one of the arguments contains the float value nan. same warning, same chaos potential. πŸ™ˆ

and that's the whole page bestie!! ✨ generated by OCamldoc on 2026-06-22, and the page itself is Stdlib.Repr(3) πŸŽ€ β€” go forth and compare responsibly, ily, mwah πŸ’‹πŸ’–

πŸ“¦ where this page comes from