Module Print
module Print:Signatures and helper functions for pretty-printing.sig
..end
This module follows the standard OCaml pretty-printing facility provided in
the module Format
of the standard library. In particular, pretty-printing
commands assume that there is an opened pretty-printing box. This permits
more flexibility, since the choice of the enclosing pretty-printing box may
depend on the context.
See also Format
module type PRINTABLE_TYPE =sig
..end
Signature for a type equipped with a pretty-printing function.
val string_converter_from_printer : (Format.formatter -> 'a -> unit) -> 'a -> string
Transform a pretty-printer into a string converter.
val list_printer_from_printer : (unit, Format.formatter, unit) format ->
(Format.formatter -> 'a -> unit) -> Format.formatter -> 'a list -> unit
list_printer_from_printer sep printer
returns a pretty-printer for lists of
type 'a list
, given a separator format sep
and a pretty-printer printer
for values of type 'a
. The resulting pretty-printer prints each element of
its argument list and prints sep
between each element. Each element in the
list is printed in a new enclosing pretty-printing box.
In other words, list_printer_from_printer sep printer fmt [a1; ...; aN]
is
equivalent to begin
Format.fprintf fmt "@[%a@]" printer a1 ;
Format.fprintf fmt sep ;
... ;
Format.fprintf fmt sep ;
Format.fprintf fmt "@[%a@]" printer aN
end
.
Note that the separator sep
may contain pretty-printing commands. For
instance ";@ "
could be used as a separator argument to this function.val array_printer_from_printer : (unit, Format.formatter, unit) format ->
(Format.formatter -> int * 'a -> unit) ->
Format.formatter -> 'a array -> unit
array_printer_from_printer sep printer
returns a pretty-printer for arrays
of type 'a array
, given a separator format sep
and a pretty-printer
printer
for values of type int * 'a
. The resulting pretty-printer prints
each pair (i, a.(i))
of its argument array a
and prints sep
between
each pair. Each pair in the array is printed in a new enclosing
pretty-printing box.
In other words, array_printer_from_printer sep printer fmt [|a1; ...; aN|]
is equivalent to begin
Format.fprintf fmt "@[%a@]" printer (0, a1) ;
Format.fprintf fmt sep ;
... ;
Format.fprintf fmt sep ;
Format.fprintf fmt "@[%a@]" printer (N-1, aN)
end
.
Note that the separator sep
may contain pretty-printing commands. For
instance ";@ "
could be used as a separator argument to this function.