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 doc sends the format instruction of doc to the Format’s formatter doc. 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 with Format_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 β€” The kmsg half of that same β€œproduce a document from a format string and its argument” situation πŸŽ€
  • printf β€” val printf : ('a, printer0) fmt -> 'a β€” Together with Format_doc.Doc.kprintf, this produces a printer from a format string and its argument πŸ”₯
  • kprintf β€” val kprintf : (t -> 'b) -> ('a, t -> 'b) fmt -> 'a β€” The kprintf half of that same β€œproduce a printer from a format string and its argument” duo πŸ’«
  • open_box β€” val open_box : box_type -> int -> printer0 β€” The open_box printer. 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 β€” The close_box printer, mirroring Format without the pp_print_ prefix ✨
  • text β€” val text : string printer β€” The text printer, mirroring Format without the pp_print_ prefix πŸ’–
  • string β€” val string : string printer β€” The string printer, mirroring Format without the pp_print_ prefix πŸŽ€
  • bytes β€” val bytes : bytes printer β€” The bytes printer, mirroring Format without the pp_print_ prefix πŸ¦‹
  • with_size β€” val with_size : int printer β€” The with_size printer, mirroring Format without the pp_print_ prefix 🌸
  • int β€” val int : int printer β€” The int printer, mirroring Format without the pp_print_ prefix πŸ”’
  • float β€” val float : float printer β€” The float printer, mirroring Format without the pp_print_ prefix 🫧
  • char β€” val char : char printer β€” The char printer, mirroring Format without the pp_print_ prefix πŸ“
  • bool β€” val bool : bool printer β€” The bool printer, mirroring Format without the pp_print_ prefix πŸ’€
  • space β€” val space : printer0 β€” The space printer, mirroring Format without the pp_print_ prefix 🌈
  • cut β€” val cut : printer0 β€” The cut printer, mirroring Format without the pp_print_ prefix βœ‚οΈ
  • break β€” val break : spaces:int -> indent:int -> printer0 β€” The break printer, with spaces and indent, mirroring Format without the pp_print_ prefix πŸ’…
  • custom_break β€” val custom_break : fits:string * int * string -> breaks:string * int * string -> printer0 β€” The custom_break printer, with its fits and breaks args, mirroring Format without the pp_print_ prefix πŸŽ€
  • force_newline β€” val force_newline : printer0 β€” The force_newline printer, mirroring Format without the pp_print_ prefix ⭐
  • if_newline β€” val if_newline : printer0 β€” The if_newline printer, mirroring Format without the pp_print_ prefix πŸŒ™
  • flush β€” val flush : printer0 β€” The flush printer, mirroring Format without the pp_print_ prefix 🚿
  • force_stop β€” val force_stop : printer0 β€” The force_stop printer, mirroring Format without the pp_print_ prefix πŸ›‘
  • open_tbox β€” val open_tbox : printer0 β€” The open_tbox printer, mirroring Format without the pp_print_ prefix πŸ“¦
  • set_tab β€” val set_tab : printer0 β€” The set_tab printer, mirroring Format without the pp_print_ prefix πŸ“
  • tab β€” val tab : printer0 β€” The tab printer, mirroring Format without the pp_print_ prefix ➑️
  • tab_break β€” val tab_break : width:int -> offset:int -> printer0 β€” The tab_break printer, with width and offset, mirroring Format without the pp_print_ prefix πŸ’«
  • close_tbox β€” val close_tbox : printer0 β€” The close_tbox printer, mirroring Format without the pp_print_ prefix 🎁
  • open_tag β€” val open_tag : stag printer β€” The open_tag printer, mirroring Format without the pp_print_ prefix 🏷️
  • close_tag β€” val close_tag : printer0 β€” The close_tag printer, mirroring Format without the pp_print_ prefix πŸ”–
  • list β€” val list : ?sep:printer0 -> 'a printer -> 'a list printer β€” The list printer, with optional ?sep, mirroring Format without the pp_print_ prefix πŸ“‹
  • iter β€” val iter : ?sep:printer0 -> iter:(('a -> unit) -> 'b -> unit) -> 'a printer -> 'b printer β€” The iter printer, with optional ?sep and iter, mirroring Format without the pp_print_ prefix πŸ”
  • array β€” val array : ?sep:printer0 -> 'a printer -> 'a array printer β€” The array printer, with optional ?sep, mirroring Format without the pp_print_ prefix 🧺
  • seq β€” val seq : ?sep:printer0 -> 'a printer -> 'a Seq.t printer β€” The seq printer, with optional ?sep, mirroring Format without the pp_print_ prefix 🌊
  • option β€” val option : ?none:printer0 -> 'a printer -> 'a option printer β€” The option printer, with optional ?none, mirroring Format without the pp_print_ prefix πŸŒ—
  • result β€” val result : ok:'a printer -> error:'e printer -> ('a, 'e) result printer β€” The result printer, with ok and error, mirroring Format without the pp_print_ prefix βœ…βŒ
  • either β€” val either : left:'a printer -> right:'b printer -> ('a, 'b) Either.t printer β€” The either printer, with left and right, mirroring Format without the pp_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 β€” The align_prefix2 function with signature t * 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