package pprint

  1. Overview
  2. Docs

This module offers document combinators that help print OCaml values. The strings produced by rendering these documents are supposed to be accepted by the OCaml parser as valid values.

These functions do not distinguish between mutable and immutable values. They do not recognize sharing, and do not incorporate a protection against cyclic values.

type constructor = string
type type_name = string
type record_field = string
type tag = int
val variant : type_name -> constructor -> tag -> document list -> document

variant _ dc _ args represents a constructed value whose data constructor is dc and whose arguments are args. The other two parameters are presently unused.

val record : type_name -> (record_field * document) list -> document

record _ fields represents a record value whose fields are fields. The other parameter is presently unused.

val tuple : document list -> document

tuple args represents a tuple value whose components are args.

val string : string -> document

string s represents the literal string s.

val int : int -> document

int i represents the literal integer i.

val int32 : int32 -> document

int32 i represents the literal 32-bit integer i.

val int64 : int64 -> document

int64 i represents the literal 64-bit integer i.

val nativeint : nativeint -> document

nativeint i represents the literal native integer i.

val float : float -> document

float f represents the literal floating-point number f.

val char : char -> document

char c represents the literal character c.

val bool : bool -> document

bool b represents the Boolean value b.

val unit : document

unit represents the unit constant ().

val option : ('a -> document) -> 'a option -> document

option f o represents the option o. The representation of the element, if present, is computed by the function f.

val list : ('a -> document) -> 'a list -> document

list f xs represents the list xs. The representation of each element is computed by the function f. If the whole list fits on a single line, then it is printed on a single line; otherwise each element is printed on a separate line.

val flowing_list : ('a -> document) -> 'a list -> document

flowing_list f xs represents the list xs. The representation of each element is computed by the function f. As many elements are possible are printed on each line.

val array : ('a -> document) -> 'a array -> document

array f xs represents the array xs. The representation of each element is computed by the function f. If the whole array fits on a single line, then it is printed on a single line; otherwise each element is printed on a separate line.

val flowing_array : ('a -> document) -> 'a array -> document

flowing_array f xs represents the array xs. The representation of each element is computed by the function f. As many elements are possible are printed on each line.

val ref : ('a -> document) -> 'a Stdlib.ref -> document

ref r represents the reference r. The representation of the content is computed by the function f.

val unknown : type_name -> 'a -> document

unknown t _ represents an unknown value of type t. It is rendered as a string of the form <abstr:t>.