Format_doc(3)
β¨ NAME β¨
Format_doc β composable document for the Format formatting engine.
Bestie, welcome to the Format_doc(3) page from the OCaml library β we're doing docs but make it cute. π
π§© Module π§©
Module Format_doc
π Documentation π
Module Format_doc : sig end
Composable document for the Format formatting engine.
This module introduces a pure and immutable document type which represents a sequence of formatting instructions to be printed by a formatting engine at later point. At the same time, it also provides format string interpreter which produces this document type from format string and their associated printers.
The module is designed to be source compatible with code defining format printers: replacing Format by Format_doc in your code will convert Format printers to Format_doc printers.
module Doc : sig end β definitions and immutable API for composing documents.
π Compatibility API π
The functions and types below provides source compatibility with format printers and conversion function from Format_doc printers to Format printers. The reverse direction is implemented using an escape hatch in the formatting instruction and should only be used to preserve backward compatibility.
type doc = Doc.ttype t = doctype formattertype 'a printer = formatter -> 'a -> unitval formatter : doc ref -> formatterβformatter rdoccreates aFormat_doc.formatterthat updates therdocreference.type 'a format_printer = Format.formatter -> 'a -> unitβ translate aFormat_docprinter to aFormatone.val compat : 'a printer -> 'a format_printerval compat1 : ('p1 -> 'a printer) -> 'p1 -> 'a format_printerval compat2 : ('p1 -> 'p2 -> 'a printer) -> 'p1 -> 'p2 -> 'a format_printerval deprecated_printer : (Format.formatter -> unit) -> formatter -> unitβ if necessary, embed aFormatprinter inside a formatting instruction stream.val deprecated : 'a format_printer -> 'a printerval deprecated1 : ('p1 -> 'a format_printer) -> 'p1 -> 'a printer
π¨ Warning:deprecated_printerbreaks every guarantees provided byFormat_doc.
πͺ Format string interpreters πͺ
val fprintf : formatter -> ('a, formatter, unit) format -> 'aval kfprintf : (formatter -> 'a) -> formatter -> ('b, formatter, unit, 'a) format4 -> 'bval asprintf : ('a, formatter, unit, string) format4 -> 'aval kasprintf : (string -> 'a) -> ('b, formatter, unit, 'a) format4 -> 'bval dprintf : ('a, formatter, unit, formatter -> unit) format4 -> 'aval kdprintf : ((formatter -> unit) -> 'a) -> ('b, formatter, unit, 'a) format4 -> 'bval doc_printf : ('a, formatter, unit, doc) format4 -> 'a
Heads up bestie: Format_doc.doc_printf and Format_doc.kdoc_printf creates a document directly.
val kdoc_printf : (doc -> 'r) -> ('a, formatter, unit, 'r) format4 -> 'a
π«Ά Compatibility with Format_doc.Doc π«Ά
val doc_printer : 'a printer -> 'a Doc.printerval pp_doc : doc printer
𧬠Source compatibility with Format π§¬
β¨ String printers β¨
val pp_print_string : string printerval pp_print_substring : pos:int -> len:int -> string printerval pp_print_text : string printerval pp_print_bytes : bytes printerval pp_print_as : formatter -> int -> string -> unitval pp_print_substring_as : pos:int -> len:int -> formatter -> int -> string -> unit
π Primitive type printers π
val pp_print_char : char printerval pp_print_int : int printerval pp_print_float : float printerval pp_print_bool : bool printerval pp_print_nothing : unit printer
π§° Printer combinators π§°
val pp_print_iter : ?pp_sep:unit printer -> (('a -> unit) -> 'b -> unit) -> 'a printer -> 'b printerval pp_print_list : ?pp_sep:unit printer -> 'a printer -> 'a list printerval pp_print_array : ?pp_sep:unit printer -> 'a printer -> 'a array printerval pp_print_seq : ?pp_sep:unit printer -> 'a printer -> 'a Seq.t printerval pp_print_option : ?none:unit printer -> 'a printer -> 'a option printerval pp_print_result : ok:'a printer -> error:'e printer -> ('a, 'e) result printerval pp_print_either : left:'a printer -> right:'b printer -> ('a, 'b) Either.t printer
π¦ Boxes and tags π¦
val pp_open_stag : Format.stag printerval pp_close_stag : unit printerval pp_open_box : int printerval pp_close_box : unit printer
βοΈ Break hints βοΈ
val pp_print_space : unit printerval pp_print_cut : unit printerval pp_print_break : formatter -> int -> int -> unitval pp_print_custom_break : formatter -> fits:string * int * string -> breaks:string * int * string -> unit
π Tabulations π
val pp_open_tbox : unit printerval pp_close_tbox : unit printerval pp_set_tab : unit printerval pp_print_tab : unit printerval pp_print_tbreak : formatter -> int -> int -> unit
π Newlines and flushing π
val pp_print_if_newline : unit printerval pp_force_newline : unit printerval pp_print_flush : unit printerval pp_print_newline : unit printer
π§βπ» Compiler specific functions π§βπ»
Separators
val comma : unit printerval semicolon : unit printer
Compiler output
val pp_two_columns : ?sep:string -> ?max_lines:int -> formatter -> (string * string) list -> unit
pp_two_columns ?sep ?max_lines ppf l prints the lines in l as two columns separated by sep ("|" by default). max_lines can be used to indicate a maximum number of lines to print -- an ellipsis gets inserted at the middle if the input has too many lines.
Example:
pp_two_columns ~max_lines:3 Format.std_formatter [ "abc", "hello";
"def", "zzz"; "a" , "bllbl"; "bb" , "dddddd"; ]
prints
abc | hello ... bb | dddddd
Big bye bestie π β this page was served by OCamldoc, dated 2026-06-22, for Format_doc(3). Periodt. π
π¦ 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