Module Util.Pp

Pretty-printing combinators that generate valid OCaml syntax for common types along with combinators for user-defined types

type 'a t = bool -> Stdlib.Format.formatter -> 'a -> unit

The type of pretty-printers to valid OCaml syntax. The bool argument asks the printer to wrap its output inside parentheses if it produces a non-atomic expression.

val to_show : 'a t -> 'a -> string

to_show pp converts a pretty-printer to a simple 'a -> string function.

val of_show : ('a -> string) -> 'a t

of_show show uses a simple 'a -> string function as a pretty-printer. Unfortunately, it will wrap the resulting string with parentheses in more cases than strictly necessary.

val cst0 : string -> Stdlib.Format.formatter -> unit

cst0 name fmt pretty-prints a constructor name with no argument.

val cst1 : 'a t -> string -> bool -> Stdlib.Format.formatter -> 'a -> unit

cst1 pp name par v fmt pretty-prints a constructor name with one parameter, using pp to pretty-print its argument v, wrapping itself into parentheses when par.

val cst2 : 'a t -> 'b t -> string -> bool -> Stdlib.Format.formatter -> 'a -> 'b -> unit

cst2 pp1 pp2 name par v1 v2 fmt pretty-prints a constructor name with two parameters, using ppi to pretty-print its argument vi, wrapping itself into parentheses when par.

val cst3 : 'a t -> 'b t -> 'c t -> string -> bool -> Stdlib.Format.formatter -> 'a -> 'b -> 'c -> unit

cst3 pp1 pp2 pp3 name par v1 v2 v3 fmt pretty-prints a constructor name with three parameters, using ppi to pretty-print its argument vi, wrapping itself into parentheses when par.

val pp_exn : exn t

Pretty-printer for exceptions reusing the standard Printexc.to_string. The exception message will be wrapped conservatively (ie too often) in parentheses.

val pp_unit : unit t

Pretty-printer for type unit

val pp_bool : bool t

Pretty-printer for type bool

val pp_int : int t

Pretty-printer for type int

val pp_int64 : int64 t

Pretty-printer for type int64

val pp_float : float t

Pretty-printer for type float

val pp_char : char t

Pretty-printer for type char

val pp_string : string t

Pretty-printer for type string

val pp_bytes : bytes t

Pretty-printer for type bytes

val pp_option : 'a t -> 'a option t

pp_option pp pretty-prints a value of type 'a option using pp to pretty-print values of type 'a.

val pp_result : 'o t -> 'e t -> ('o, 'e) Stdlib.result t

pp_result pp_ok pp_error pretty-prints a value of type ('o, 'e) result using pp_ok to pretty-print values of type 'o and pp_error for values of type 'e.

val pp_pair : 'a t -> 'b t -> ('a * 'b) t

pp_pair pp_a pp_b pretty-prints a value of type 'a * 'b using pp_a to pretty-print values of type 'a and pp_b for values of type 'b.

val pp_list : 'a t -> 'a list t

pp_list pp pretty-prints a list using pp to pretty-print its elements.

val pp_seq : 'a t -> 'a Stdlib.Seq.t t

pp_seq pp pretty-prints a sequence using pp to pretty-print its elements.

val pp_array : 'a t -> 'a array t

pp_array pp pretty-prints an array using pp to pretty-print its elements.

type pp_field

The abtract type for the pretty-printer of a record field

val pp_field : string -> 'a t -> 'a -> pp_field

pp_field name pp v build a pretty-printer for a record field of given name using pp to pretty-print its content value v.

val pp_record : pp_field list t

pp_record flds pretty-prints a record using the list of pretty-printers of its fields.