package pprint

  1. Overview
  2. Docs

Module PPrint.OCamlSource

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.

Sourcetype constructor = string
Sourcetype type_name = string
Sourcetype record_field = string
Sourcetype tag = int
Sourceval 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.

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

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

Sourceval tuple : document list -> document

tuple args represents a tuple value whose components are args.

Sourceval string : string -> document

string s represents the literal string s.

Sourceval int : int -> document

int i represents the literal integer i.

Sourceval int32 : int32 -> document

int32 i represents the literal 32-bit integer i.

Sourceval int64 : int64 -> document

int64 i represents the literal 64-bit integer i.

Sourceval nativeint : nativeint -> document

nativeint i represents the literal native integer i.

Sourceval float : float -> document

float f represents the literal floating-point number f.

Sourceval char : char -> document

char c represents the literal character c.

Sourceval bool : bool -> document

bool b represents the Boolean value b.

Sourceval unit : document

unit represents the unit constant ().

Sourceval 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.

Sourceval 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.

Sourceval 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.

Sourceval 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.

Sourceval 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.

Sourceval ref : ('a -> document) -> 'a ref -> document

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

Sourceval 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>.