title: How do I inspect the in-memory representation of OCaml values?
body: <p>Is there any way to inspect the in-memory representation of OCaml values <em>in OCaml</em>, without using something like gdb? Ideally, the output would give me either hex bytes or binary bits, similar to what you can get via gdb.</p>
  
  <p>The <a href="https://caml.inria.fr/pub/docs/manual-ocaml/libref/Obj.html" rel="nofollow noreferrer">Obj module</a> looks promising, and <a href="https://dev.realworldocaml.org/runtime-memory-layout.html" rel="nofollow noreferrer">Real World OCaml has a section about it</a>, but does it offer a single way to get in-memory representation, without having to know how every OCaml value is laid out in memory?</p>