Module Monolith.Print
The submodule Print
offers facilities for printing OCaml values and expressions.
type '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.
val int : int printer
int
is an integer literal printer. It is safe.
val bool : bool printer
bool
is a Boolean literal printer. It is safe.
val char : char printer
char
is a character literal printer. It is safe.
val string : string printer
string
is a string literal printer. It is safe.
val result : 'a printer -> 'b printer -> ('a, 'b) Stdlib.result printer
result
is a result printer. It is safe.
val 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.
val apply : document -> document list -> document
apply doc docs
constructs an OCaml application ofdoc
to the list of argumentsdocs
. 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.
val assert_ : document -> document
assert_ doc
constructs an OCaml assertion, that is, an application of the variableassert
to the documentdoc
, surrounded with parentheses. This combinator is unsafe: the assertion is not parenthesized.
val comment : document -> document
comment doc
prints the documentdoc
inside a comment (preceded with a breakable space). It is safe.
val candidate_finds : document -> document
candidate_finds doc
prints the documentdoc
inside a comment of the form(* candidate finds _ *)
. See e.g. the demodemos/working/bag
for an example of its use. It is safe.