Map(3)
π Map(3) π
okay so bestie, welcome to the Map page from the OCaml library manual β yes that's the whole header, Map(3) and all, we're not copying it, we're curating it β¨
πΈ NAME πΈ
Map β association tables over ordered types. that's it, that's the vibe π
π¦ Module π¦
the module is literally called Module Map. main character energy fr π
π Documentation π
so it's Module Map, and it has this thing : sig end β yeah, sig end, iconic, we love a signature π«Ά
β¨ the whole concept β¨
Association tables over ordered types. π
this module implements applicative association tables, also known as finite maps or dictionaries (iykyk), and you get all of that given a total ordering function over the keys. the keys need a total order, that's the whole deal π₯
and listen β all operations over maps are purely applicative (no side-effects). no sneaky mutation, no surprises, no cap. π
the implementation uses balanced binary trees, which is why searching and insertion take time logarithmic in the size of the map. logarithmic bestie, that's the good stuff β
π for instance π
okay so here's the example, and it ate:
module IntPairs =
struct
type t = int * int
let compare (x0,y0) (x1,y1) =
match Stdlib.compare x0 x1 with
0 -> Stdlib.compare y0 y1
| c -> c
end
module PairsMap = Map.Make(IntPairs)
let m = PairsMap.(empty |> add (0,1) "hello" |> add (1,0) "world")
so what's happening here? this creates a new module PairsMap, with a new type 'a PairsMap.t of maps from int * int to 'a. in this example, m contains string values, so its type is string PairsMap.t. literally that simple, slay π
β¨
π§ the module types π§
module type OrderedType = sig endβ input signature of the functorMap.Make. yes,sig end. yes, it's empty-looking here. yes, it's still important πmodule type S = sig endβ output signature of the functorMap.Make. alsosig end. balance π
π the functor π
module Make : (Ord : OrderedType) -> sig endβ functor building an implementation of the map structure given a totally ordered type. like, you hand it anOrdthat's anOrderedType, and it hands you back asig end. that's the trade, that's the deal, periodt π
ngl, the sig ends look like a lot of nothing, but that's exactly what the page says, so we're keeping them exactly as-is bestie π«Ά
and that's the whole page! π source/version and date realness: this came from OCamldoc, dated 2026-06-22, and it's page Map(3). mwah, go build some balanced binary trees πππ¦
π¦ 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