Format.Args(3)
π NAME π
okay so bestie, this is Format.Args from the OCaml library β and it's literally the module that defines a heterogeneous list type, which you can hand straight to printf-like functions. no cap, that's the whole vibe. π
π¦ Module π¦
the module is called Format.Args, and its signature is just : sig end β yes girl, that's the whole thing, it's giving minimalism β¨
πΈ Documentation πΈ
π Module Args
: sig end β iconic, we love a signature that keeps it mysterious π«Ά
so like, the Args module defines a heterogeneous list type, and you use it as the argument of printf-like functions. that's it, that's the function. π
here's the part that's lowkey the best: you do not need to open this module when you're using the functions that accept an Args.t. thanks to type-based disambiguation, the type gets inferred automatically β so the list syntax [x; y; z] works directly for heterogeneous lists. no open, no ceremony, just vibes. π§β¨
seriously, don't open it, it's not required β the compiler just gets you. iykyk π
π an example π
(* without opening Args *)
Format.lprintf "%s %d %.02f@." [ "ocaml"; 42; 3.14 ]
(* or with explicit construction *)
let lst = let open Format.Args in "ocaml" :: [ 42; 3.14 ] @ [ 'c' ] in
Format.lprintf "%s %d %.02f %c@." lst
see how the first one just... works? three totally different types in one list, no drama. and the second one shows you the explicit-construction route if you're feeling main character energy. both ate. π₯
π Since 5.5 π
this dropped in 5.5, so if you're on something older, sorry bestie, no list magic for you π
β the type, fr fr β
type ('a, 'r) t =
| [] : ('r0, 'r0) t
| (::) : 'a0 * ('b, 'r1) t -> ('a0 -> 'b, 'r1) t
okay look at that GADT. [] is the empty case, and (::) conses one element 'a0 onto a tail and the whole thing becomes ('a0 -> 'b, 'r1) t. it's literally building up a function type, one element at a time. the way that this type-checks... obsessed. π
π the values π
val apply : 'a -> ('a, 'r) t -> 'rβ you give it a value and anArgs.t, and it gives you back an'r. that's the apply, bestie, that's the whole plot π¦val (@) : ('a, 'r1) t -> ('r1, 'r2) t -> ('a, 'r2) tβ the append operator, concatenating twoArgs.t-shaped things into one, threading'r1through the middle. slay. β¨
π reminder:@here is theFormat.Argsone, working onArgs.tvalues β don't go confusing it with the list append you already know, they're different girlies.
and that's the whole page! love that for us. periodt. π
this lil sign-off is brought to you by OCamldoc, dated 2026-06-22, serving you Format.Args(3) realness πβ¨π
π¦ 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