MoreLabels.Hashtbl.HashedType(3)

πŸ’… MoreLabels.Hashtbl.HashedType(3) β€” the OCaml library page, bestie edition

okay so this is a page from the OCaml library manual, and it's literally the whole MoreLabels.Hashtbl.HashedType(3) moment. it's not a big dramatic page, it's a module type, but it's foundational β€” the vibe check that every hashtable key has to pass before it's allowed in. iykyk ✨


🌸 NAME 🌸

MoreLabels.Hashtbl.HashedType β€” the input signature of the functor MoreLabels.Hashtbl.Make. that's it, that's the job, and it eats. πŸ’…


πŸŽ€ Module type πŸŽ€

so, the whole thing, the entire module type, is literally this:

Module type   MoreLabels.Hashtbl.HashedType

she's a module type, she's small, she's powerful, she's main character energy. 🫢


✨ Documentation ✨

Module type HashedType
 = sig end

okay yes it looks empty from the outside and that's the joke β€” the meat is all in the members below. it's the input signature of the functor MoreLabels.Hashtbl.Make β€” so like, before you can call that functor, you gotta hand it a module matching this shape. no cap, that's the entire contract. πŸ’–

🌈 type t

the type of the hashtable keys. your keys, your type, your world, bestie. πŸ¦‹

🧚 val equal : t -> t -> bool

the equality predicate used to compare keys. yes she's back, yes she compares keys, yes you have to actually mean it.

⭐ val hash : t -> int

a hashing function on keys. now listen β€” this is the part where you can NOT be sloppy:

  • it must be such that if two keys are equal according to equal, then they have identical hash values as computed by hash. periodt. if your equal says "same" but your hash says "different", the whole table goes feral and it's giving chaos. πŸ’€
  • the hash value of a key should remain constant as long as the key is in the table. in particular, if the hash function depends on mutable key data, then that data must not be mutated while the key is in the table. do not touch the key. leave her alone. she is busy being hashed. πŸ”₯
  • similarly, as the hash function may be called while the table itself is being modified, it should avoid accessing the table as part of its computation. like, don't reach into the bowl while the bowl is being stirred. that's not a good look. πŸ™ˆ
fr fr: those two caveats are real. ignore them and you get the undefined-behaviour girlies showing up uninvited. 🩷

πŸŽ€ Examples: suitable (equal, hash) pairs πŸŽ€

for arbitrary key types, the iconic combos include:

  • ((=), MoreLabels.Hashtbl.HashedType.hash) β€” for comparing objects by structure (provided objects do not contain floats). lowkey the default choice, but mind the no-floats thing, bestie, that's a real constraint. 😭
  • ((fun x y -> compare x y = 0), MoreLabels.Hashtbl.HashedType.hash) β€” for comparing objects by structure and handling nan correctly. yes this one gets it, this one does the nan thing right. slay. πŸ‘‘
  • ((==), MoreLabels.Hashtbl.HashedType.hash) β€” for comparing objects by physical equality (e.g. for mutable or cyclic objects). the "same actual object or nothing" girlie. perfect for when structure comparison would just loop forever. πŸŒ€

✨ that's the whole page, bestie β€” every flag, every function, every caveat, nothing skipped ✨

this gem dropped from OCamldoc on 2026-06-22, and the page you just read is MoreLabels.Hashtbl.HashedType(3). take her, love her, keep your hashes constant. mwah. πŸ’œπŸŽ€πŸ¦‹

πŸ“¦ where this page comes from