Local_store(3)
π Local_store π
okay so bestie, welcome to Local_store, fresh from the OCaml library manual. This module is literally your little save-point system for refs and hash tables: it gives you facilities for creating references (and hash tables) that can easily be snapshotted and restored to an arbitrary version. Obsessed. π
β¨ NAME β¨
Local_store β the module that provides some facilities for creating references (and hash tables) which can easily be snapshotted and restored to an arbitrary version. No cap, that's the whole assignment.
π§ MODULE π§
Module name: Local_store. That's it, that's the module. π«Ά
π DOCUMENTATION π
Module Local_store : sig end
This module provides some facilities for creating references (and hash tables) which can easily be snapshotted and restored to an arbitrary version.
It is used throughout the frontend (read: typechecker), to register all (well, hopefully) the global state. Thus making it easy for tools like Merlin to go back and forth typechecking different files. Iconic behavior, honestly. β¨
π Creators π
val s_ref : 'a -> 'a refβ Similar toref, except the allocated reference is registered into the store.val s_table : ('a -> 'b) -> 'a -> 'b refβ Used to register hash tables. Those also need to be placed into refs to be easily swapped out, but one can't just "snapshot" the initial value to create fresh instances, so instead an initializer is required.
Use it like this:
let my_table = s_table Hashtbl.create 42
π State management π
Note: all the following functions are currently unused inside the compiler codebase. Merlin is their only user at the moment.
type storeval fresh : unit -> storeβ Returns a fresh instance of the store.
The first time this function is called, it snapshots the value of all the registered references, later calls to fresh will return instances initialized to those values.
val with_store : store -> (unit -> 'a) -> 'aβwith_store s fresets all the registered references to the value they have insfor the run off. Iffupdates any of the registered refs,sis updated to remember those changes.val reset : unit -> unitβ Resets all the references to the initial snapshot (i.e. to the same values that new instances start with).val is_bound : unit -> boolβ Returnstruewhen a store is active (i.e. when called from the callback passed toLocal_store.with_store),falseotherwise.
that's the whole vibe, bestie β page cooked by OCamldoc, dated 2026-06-22, for Local_store(3). π
β¨
π¦ 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