Module Rtt_ops

module Rtt_ops: sig .. end
Implementation of RTT functions.

The functions Rtt_ops.pprint, Rtt_ops.to_string, ... should be used straightforwardly in user programs with the interface described here. They are implemented on top of Rtt_untype without any other "magic". The implementation of Rtt_ops.bprint is a simple example of using Rtt_untype to perform untyped matching.

The nortt implementation returns stubs like "<nortt>" instead.

Generic printing functions

val to_string : 'a -> string
Return a string representation of a value, in one line (possibly very long). Does not terminate on cyclic data structures.
val bprint : 'a -> Buffer.t -> unit
Print a value in the given buffer (without any formatting). Does not terminate on cyclic data structures.
val pprint : ?depth:int -> ?unfold:bool -> 'a -> Format.formatter -> unit
Pretty-print a value on the given formatter. Some types are printed in a more readable way, according to the custom printers registered with Rtt_ops.register_printer. Custom printers are registered by default for the standard data types: If a depth argument is provided, the depth of printing is limited to this bound. note that all elements in lists, in and the above standard data types are considered to have the same depth (the depth of the container + 1).

Physical sharing is explicited by naming nodes with multiple predecessors. This allows the printing of cyclic data structures in paricular. This behavior is disabled if unfold is set to true. This is faster, but will not terminate on cyclic data structures unless a depth is specified (and this will definitely not terminate on cyclic lists as list elements are considered to have the same depth.

val pprint_raw : 'a -> Format.formatter -> unit
Pretty-print a value on the given formatter. Only lists are treated specially and printed as [x, y].
type table 
val register_printer : (Rtt_untype.untyped ->
(depth:int ->
table:table option -> prefix:string -> Format.formatter -> unit)
option) ->
Register a custom pretty-printer for use in Rtt_ops.pprint. It must be a function which takes an untyped value and returns either None (to let another printer apply to it), or Some f where f will print this value, calling recursively Rtt_ops.pprint_value if required (with same depth and table appropriate prefix). depth will be automatically decremented by one, and thus does not need to be changed unless Rtt_ops.pprint_value is invoked on values deeper than direct sub-values. Printers are tried in order starting with the most recently registered.
val pprint_value : depth:int ->
table:table option ->
?prefix:string -> Format.formatter -> Rtt_untype.untyped -> unit
Print an untyped value as Rtt_ops.pprint prints a typed value, with the given prefix before the value. If the value and prefix fit on the same, then they are printed this way without additional space inbetween. Otherwise, the printer will either print the prefix, break line, indent and print the value, or, if the value is a list with an opening and closing keywords (e.g., a record or tuple), add the prefix to the opening string.

Advanced use

The following modules allow to extend the mutually recursive definitions implementing the printing functions in the most generic way. Multiple independent printers can be defined. The idea is that the mutually recursive printers are defined as the fixpoint of a functor from the module type Pprint or Rtt_ops.Pprint_bounded to itself. So, the definition can be extended by writing a new functor which "includes" a more simple one and then redefines some of its fields. See the source code of Rtt_ops.Pprint_raw_fix, Rtt_ops.Pprint_bounded_fix, and Rtt_ops.Pprint_bounded_fix for an example.

Remark: objects offer a simpler alternative for manipulating extensible mutually recursive definitions, but they are not supported by RTT, and we don't need dynamic dispatch here.

module type Pprint_raw = sig .. end
module type Pprint_bounded = sig .. end
val create_table : unit -> table
module Pprint_raw_fix: 
functor (Pprint_raw : Pprint_raw) -> Pprint_raw
Definition of Rtt_ops.pprint_raw
module Pprint_bounded_fix: 
functor (Pprint_bounded : Pprint_bounded) -> Pprint_bounded
Adds depth bounding to Rtt_ops.Pprint_raw_fix
module Pprint_fix: 
functor (Pprint_bounded : Pprint_bounded) -> Pprint_bounded
Definition of Rtt_ops.pprint, using Rtt_ops.Pprint_bounded_fix