Legend:
Library
Module
Module type
Parameter
Class
Class type
Pretty printing of documents.
A document is a structured tree of text with formatting instructions.
It can be rendered into a string ("pretty printed"), see Pretty.
This follows Wadler's paper "A prettier printer", but with some changes in the rendering part because we can't rely on lazyness to make the algebraic implementation efficient.
Some general considerations: the type t is the type of documents, a tree with text leaves that is pretty printed within a given width.
Layout is controlled via the combination of a few primitives:
newline will either print a space or a newline. It is similar to Format's "@ " in that sense. A big difference with Format is that by default newline is actually a newline. It only becomes a space if it's in a group small enough to fit in the remainder of the current line.
group d tries to write d on a single line if there's room. If not, it has no effect.
nest n d increases the indentation level inside d. Any newline that is rendered as a new line is indented by n more spaces (which are cumulative with surrounding nest calls).
append a b (or a ^ b) just prints a followed by b.
fill d is a bit like group but it will try to cram as much as possible on each line. It is not all-or-nothing like group.
It is a document that has the same shape (and size) as d, except that additional data will be output when it is rendered using extension e.
When this is rendered, first e.pre out v is called; then d is printed; then e.post out v is called. Here out is the output buffer/stream for rendering.