Library
Module
Module type
Parameter
Class
Class type
"Caml Object Notation", a library for pretty-printing ocaml values with sharing.
Unique identifiers to make sharing explicit. Variable names are automatically generated.
type var = id
type t =
The output is the syntax of OCaml values (with unique identifiers for structured values) extended with variables and let-bindings to represent sharing.
Primitive values
val unit : t
print `()`
val bool : bool -> t
print `true` or `false`
val char : char -> t
print a single quoted character, escaped if necessary
val int : int -> t
print an integer
val int32 : int32 -> t
print a 32-bit integer
val int64 : int64 -> t
print a 64-bit integer
val nativeint : nativeint -> t
print a native integer
val float : float -> t
print a floating point value
val string : string -> t
print a double quoted string, with necessary escapes
val constant : string -> t
print a literal string (without quoting), useful for non-parameterized data constructors. constant "None"
prints `None`.
print a parameterized dataconstructor. constructor "Some" unit
prints `Some ()`.
print an OCaml record. record ["a", int 1; "b", bool false]
prints `a: 1, b: false
`.
construct a cons cell. cons (int 1) nil
prints `1
`, cons (int 1) (constant "xs")
prints `1 :: xs`,
Shortcut for a data constructor with multiple arguments. construct "None" []
= constant "None"
prints `None`, construct "Some" [int 1]
= constructor "Some" (int 1)
prints `Some 1`, construct "A" [int 1; int 2] = [constructor "A" (tuple [int 1; int 2])]
prints `A (1, 2)`.
Shortcut for constructor with inline record. crecord "A" ["a", int 1; "b", bool false]
prints `A a: 1, b: false
`.
val nil : t
nil prints ``
list xs
= List.fold_right cons xs nil
. list [int 1; int 2; int 3]
prints `1; 2; 3
`.
Variants that prevent sharing these values
val print_as_is : t -> PPrint.document
Print the value as it is (without changing sharing) to a PPrint.document
.
val print : t -> PPrint.document
Print the value with explicit sharing to a PPrint.document
. print t == print_as_is (explicit_sharing t)
.
val format_document : Format.formatter -> PPrint.document -> unit
Print a PPrint document on a formatter while trying to follow respect the margin specification of the formatter.
val format_as_is : Format.formatter -> t -> unit
Format the value as it is (without changing sharing) to a Format.formatter
val format : Format.formatter -> t -> unit
Format the value with explicit sharing to a Format.formatter
. format t == format_as_is (explicit_sharing t)
.
To display cmon values in a top-level, you can use #install_printer format. For instance:
utop # Cmon.unit;;