Format.Args(3)

πŸ“¦
version 5.5.0 Β· 2 versions
, in arch rolling

πŸ’… 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 an Args.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 two Args.t-shaped things into one, threading 'r1 through the middle. slay. ✨

πŸ’€ reminder: @ here is the Format.Args one, working on Args.t values β€” 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