Stdlib.Obj(3)
π Stdlib.Obj(3) β the "yes bestie we're doing unsafe stuff" module π
ok so real talk: this page lives in the OCaml library manual, and it's the one your CS prof warns you about at 2am. It's Stdlib.Obj, module Obj, which the docs literally declare as (module Stdlib__Obj). no description was given in the original, so likeβ¦ the vibe is the description, iykyk π«Ά
β¨ NAME β¨
Stdlib.Obj β no description. that's it. that's the name. she's mysterious, she's powerful, she's giving main character energy with zero explanation π
π¦ Module π¦
Module Stdlib.Obj
πΈ Documentation πΈ
girl. okay. here's the whole thing, item by item, no cap:
Module Obj
: (module Stdlib__Obj)
π the types
type tβ the abstract opaque blob type. the raw "thing" that everything secretly is.type raw_data = nativeintβ yup, raw data is just anativeint. that's the whole definition. slay.
π₯ the core functions
val repr : 'a -> tβ takes literally anything and hands you back itstrepresentation. peek behind the curtain.val obj : t -> 'aβ the reverse glow-up: turn atback into "some'a". trust the process (and the type system, which is being very brave right now).val magic : 'a -> 'bβ the iconique one. any type to any other type. it's giving chaos, it's giving power, it's giving please know what you're doing πval is_block : t -> boolβ true if it's a block, false otherwise. vibe check for blocks.val is_int : t -> boolβ true if it's an integer. vibe check for ints.val tag : t -> intβ grab the tag of the thing.val size : t -> intβ grab the size of the thing.val reachable_words : t -> intβ this one's a whole paragraph, buckle up: it computes the total size (in words, including the headers) of all heap blocks accessible from the argument. and yes, statically allocated blocks are included. she's thorough. β¨
Since 4.04 β reachable_words has been here since 4.04, periodt.
π the field accessors
val field : t -> int -> tβ read the field at that index.val set_field : t -> int -> t -> unitβ write a field at that index.
β οΈ BIG WARNING BESTIE, READ THIS ONE β οΈ when using flambda:set_fieldMUST NOT be called on immutable blocks. (blocks allocated in C stubs, or withnew_blockbelow, are always considered mutable. that's the safe zone.) the exact same rule goes forset_double_field. π§ for experts only:set_fieldet al can be made safe by first wrapping the block inSys.opaque_identity, so any information about its contents will not be propagated. that's the trick. literally the trick.
val double_field : t -> int -> floatβ read a double field.val set_double_field : t -> int -> float -> unitβ write a double field. (see the flambda warning above, it applies here too, don't act surprised π)val raw_field : t -> int -> raw_dataβ read a raw field.val set_raw_field : t -> int -> raw_data -> unitβ write a raw field.
π§ block construction & friends
val new_block : int -> int -> tβ make a fresh new block. yes, blocks made this way count as mutable. πval dup : t -> tβ duplicate it.val add_offset : t -> Int32.t -> tβ shift it by anInt32.toffset.val with_tag : int -> t -> tβ same block, different tag.
π the legendary tag constants
these are the crown jewels, list them all, don't skip a single one:
val first_non_constant_constructor_tag : intval last_non_constant_constructor_tag : intval forcing_tag : intval cont_tag : intval lazy_tag : intval closure_tag : intval object_tag : intval infix_tag : intval forward_tag : intval no_scan_tag : intval abstract_tag : intval string_tag : intval double_tag : intval double_array_tag : intval custom_tag : intval int_tag : intval out_of_heap_tag : intval unaligned_tag : int
π submodules
module Extension_constructor : sig endβ yeah, the signature's empty from out here. it's a whole thing. π€·ββοΈmodule Ephemeron : sig endβ same deal, emptysig endin this view.
π quick reminder: this whole module is the "for experts, for real, we mean it" part of the stdlib. the fact that it's documented doesn't make it a cuddle puddle. respect the blocks. π
that's the whole page, bestie, every single val, every tag, every warning, nothing skipped π«Άπβ¨
made with love by OCamldoc, dated 2026-06-22, for Stdlib.Obj(3) β go forth and be responsible with that magic π
ππ¦
π¦ 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