package monolith

  1. Overview
  2. Docs

Module Monolith.PrintSource

The submodule Print offers facilities for printing OCaml values and expressions.

Sourcetype 'a printer = 'a -> document

A printer transforms a value to into a document. A printer is said to be safe if it produces a document that is unambiguously delimited (e.g., delimited with parentheses). It is unsafe otherwise.

Sourceval int : int printer

int is an integer literal printer. It is safe.

Sourceval bool : bool printer

bool is a Boolean literal printer. It is safe.

Sourceval char : char printer

char is a character literal printer. It is safe.

Sourceval string : string printer

string is a string literal printer. It is safe.

Sourceval option : 'a printer -> 'a option printer

option is an option printer. It is safe.

Sourceval result : 'a printer -> 'b printer -> ('a, 'b) result printer

result is a result printer. It is safe.

Sourceval pair : 'a printer -> 'b printer -> ('a * 'b) printer

pair is a pair printer. It is safe.

Sourceval list : 'a printer -> 'a list printer

list is a list printer. It is safe.

Sourceval array : 'a printer -> 'a array printer

array is an array printer. It is safe.

Sourceval parens : document -> document

parens encloses its argument within a pair of parentheses. It is safe. If the document thus obtained does not fit a single line, then it is split over three lines and its content is indented by two spaces.

Sourceval apply : document -> document list -> document

apply doc docs constructs an OCaml application of doc to the list of arguments docs. The arguments are separated with spaces, and if the whole application does not fit on a line, then a flowing style is adopted, inserting a line break where necessary. This combinator is unsafe: the application is not parenthesized.

Sourceval assert_ : document -> document

assert_ doc constructs an OCaml assertion, that is, an application of the variable assert to the document doc, surrounded with parentheses. This combinator is unsafe: the assertion is not parenthesized.

Sourceval comment : document -> document

comment doc prints the document doc inside a comment (preceded with a breakable space). It is safe.

Sourceval candidate_finds : document -> document

candidate_finds doc prints the document doc inside a comment of the form (* candidate finds _ *). See e.g. the demo demos/working/bag for an example of its use. It is safe.