Format_doc.Doc(3)
Format_doc.Doc(3) π OCaml library
πΈ NAME πΈ
Format_doc.Doc β Definitions and immutable API for composing documents. Thatβs the whole vibe, bestie β¨
π Module π
Module Format_doc.Doc β yes, this exact module, no cap π
β¨ Documentation β¨
Module Doc
: sig end
Definitions and immutable API for composing documents β iconic, honestly π«Ά
π§ Type definitions and core functions π§
Okay so first up, the box types. These are the format box types, and they are literally giving foundational:
type box_type =
| H
| V
| HV
| HoV
| B
Format box types β thatβs the label, bestie π
type stag = Format.stag
Then we have element, the base formatting instruction recognized by Format. Look at all these constructors, slay:
type element =
| Text of string
| With_size of int
| Open_box of {
kind : box_type ;
indent : int ;
}
| Close_box
| Open_tag of Format.stag
| Close_tag
| Open_tbox
| Tab_break of {
width : int ;
offset : int ;
}
| Set_tab
| Close_tbox
| Simple_break of {
spaces : int ;
indent : int ;
}
| Break of {
fits : string * int * string ;
breaks : string * int * string ;
}
| Flush of {
newline : bool ;
}
| Newline
| If_newline
| Deprecated of (Format.formatter -> unit)
(* Escape hatch: a Format printer used to provide
backward-compatibility for user-defined printer (from the
#install_printer toplevel directive for instance).
*)
Base formatting instruction recognized by Format β yes, thatβs what this type is π
type t β the immutable document type. Immutable! We love a stable icon π
type ('a, 'b) fmt = ('a, t, t, 'b) format4
type printer0 = t -> t
type 'a printer = 'a -> printer0
Now the values, bestie. Every single one, in order, no skipping:
emptyβval empty : tβ Empty document. The blank canvas, the clean slate, the βnot me opening a new docβ energy πΈformatβval format : Format.formatter -> t -> unitβformat ppf docsends the format instruction ofdocto the Formatβs formatterdoc. Yes, thatβs what it says π«Άfoldβval fold : ('acc -> element -> 'acc) -> 'acc -> t -> 'accβ Fold over a document as a sequence of instructions. Very βone thing at a timeβ of it πmsgβval msg : ('a, t) fmt -> 'aβ Together withFormat_doc.Doc.kmsg, this produces a document from a format string and its argument. The duo ate, honestly β¨kmsgβval kmsg : (t -> 'b) -> ('a, 'b) fmt -> 'aβ Thekmsghalf of that same βproduce a document from a format string and its argumentβ situation πprintfβval printf : ('a, printer0) fmt -> 'aβ Together withFormat_doc.Doc.kprintf, this produces a printer from a format string and its argument π₯kprintfβval kprintf : (t -> 'b) -> ('a, t -> 'b) fmt -> 'aβ Thekprintfhalf of that same βproduce a printer from a format string and its argumentβ duo π«open_boxβval open_box : box_type -> int -> printer0β Theopen_boxprinter. Opening boxes is kind of its whole main character moment π¦
Heads up, bestie: the functions below mirror Format printers, without the pp_print_ prefix naming convention. Thatβs the whole note π«Ά
close_boxβval close_box : printer0β Theclose_boxprinter, mirroring Format without thepp_print_prefix β¨textβval text : string printerβ Thetextprinter, mirroring Format without thepp_print_prefix πstringβval string : string printerβ Thestringprinter, mirroring Format without thepp_print_prefix πbytesβval bytes : bytes printerβ Thebytesprinter, mirroring Format without thepp_print_prefix π¦with_sizeβval with_size : int printerβ Thewith_sizeprinter, mirroring Format without thepp_print_prefix πΈintβval int : int printerβ Theintprinter, mirroring Format without thepp_print_prefix π’floatβval float : float printerβ Thefloatprinter, mirroring Format without thepp_print_prefix π«§charβval char : char printerβ Thecharprinter, mirroring Format without thepp_print_prefix πboolβval bool : bool printerβ Theboolprinter, mirroring Format without thepp_print_prefix πspaceβval space : printer0β Thespaceprinter, mirroring Format without thepp_print_prefix πcutβval cut : printer0β Thecutprinter, mirroring Format without thepp_print_prefix βοΈbreakβval break : spaces:int -> indent:int -> printer0β Thebreakprinter, withspacesandindent, mirroring Format without thepp_print_prefix πcustom_breakβval custom_break : fits:string * int * string -> breaks:string * int * string -> printer0β Thecustom_breakprinter, with itsfitsandbreaksargs, mirroring Format without thepp_print_prefix πforce_newlineβval force_newline : printer0β Theforce_newlineprinter, mirroring Format without thepp_print_prefix βif_newlineβval if_newline : printer0β Theif_newlineprinter, mirroring Format without thepp_print_prefix πflushβval flush : printer0β Theflushprinter, mirroring Format without thepp_print_prefix πΏforce_stopβval force_stop : printer0β Theforce_stopprinter, mirroring Format without thepp_print_prefix πopen_tboxβval open_tbox : printer0β Theopen_tboxprinter, mirroring Format without thepp_print_prefix π¦set_tabβval set_tab : printer0β Theset_tabprinter, mirroring Format without thepp_print_prefix πtabβval tab : printer0β Thetabprinter, mirroring Format without thepp_print_prefix β‘οΈtab_breakβval tab_break : width:int -> offset:int -> printer0β Thetab_breakprinter, withwidthandoffset, mirroring Format without thepp_print_prefix π«close_tboxβval close_tbox : printer0β Theclose_tboxprinter, mirroring Format without thepp_print_prefix πopen_tagβval open_tag : stag printerβ Theopen_tagprinter, mirroring Format without thepp_print_prefix π·οΈclose_tagβval close_tag : printer0β Theclose_tagprinter, mirroring Format without thepp_print_prefix πlistβval list : ?sep:printer0 -> 'a printer -> 'a list printerβ Thelistprinter, with optional?sep, mirroring Format without thepp_print_prefix πiterβval iter : ?sep:printer0 -> iter:(('a -> unit) -> 'b -> unit) -> 'a printer -> 'b printerβ Theiterprinter, with optional?sepanditer, mirroring Format without thepp_print_prefix πarrayβval array : ?sep:printer0 -> 'a printer -> 'a array printerβ Thearrayprinter, with optional?sep, mirroring Format without thepp_print_prefix π§Ίseqβval seq : ?sep:printer0 -> 'a printer -> 'a Seq.t printerβ Theseqprinter, with optional?sep, mirroring Format without thepp_print_prefix πoptionβval option : ?none:printer0 -> 'a printer -> 'a option printerβ Theoptionprinter, with optional?none, mirroring Format without thepp_print_prefix πresultβval result : ok:'a printer -> error:'e printer -> ('a, 'e) result printerβ Theresultprinter, withokanderror, mirroring Format without thepp_print_prefix β βeitherβval either : left:'a printer -> right:'b printer -> ('a, 'b) Either.t printerβ Theeitherprinter, withleftandright, mirroring Format without thepp_print_prefix β¬ οΈβ‘οΈ
π« Alignment functions π«
align_prefixβval align_prefix : (t * int) list -> t listβ Align the right side of one"@{<ralign>...@}"tag box by inserting spaces at the beginning of boxes. Those functions do nothing if the tag box appears after a break hint.
β οΈ Important little warning, bestie: those functions do nothing if the tag box appears after a break hint. Thatβs the rule π«Ά
align_prefix2βval align_prefix2 : t * int -> t * int -> t * tβ Thealign_prefix2function with signaturet * int -> t * int -> t * t. Itβs right there in the alignment-functions section, and we are not leaving it out π
Made with π by OCamldoc Β· 2026-06-22 Β· Format_doc.Doc(3) β bye bestie, go compose some documents! π«Άβ¨
π¦ 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