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
nanas different from any other float value, including itself - while
comparetreatsnanas 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.
β οΈcompareapplied to functional values may raiseInvalid_argument.compareapplied 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
- 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