Module Support.Debug

Debug-print library with up to 31 separate categories of information.

Usage:

  let (dprint, dprnt) = Debug.makeFunctions (Debug.toFlags [...])

  let (dprintf, dprint, dprnt) = Debug.makeFunctions' (Debug.toFlags [...])

where `...' is the category (or categories) specific to the module.

Then,

If debugging is turned off, print is more efficient whenever computing the string is at all nontrivial. This actually matters; running the test suite with debug mode enabled takes several times longer.

All functions will add a newline after printing your text.

type flags
val enable : unit -> unit
val is_enabled : unit -> bool
val init : string option -> unit
val makeFunctions : flags -> ((unit -> string) -> unit) * (string -> unit)
module Fmt : sig ... end

This submodule defines a record containing a higher-rank polymorphic function. We need this record type so that we can pass a partially-applied Format.fprintf function to client modules. We introduce the submodule so that client modules can selectively open it if they want to use the format-string support provided by Debug; this will bring into scope only the fmt type and the fmt projection for the record.

type 'a io = 'a -> unit
val makeFunctions' : flags -> Fmt.fmt io io * (unit -> string) io * string io
val toFlags : int list -> flags
val flag : int -> bool

Tests if a given flag is set.

val indented : Fmt.fmt io io -> int -> (unit -> 'a) -> 'a

Runs the given function with debug printing indented by the given number of spaces. Pass in dprintf obtained by calling makeFunctions'.

Note that the vbox introduced to indent will NOT be closed if the given function raises an exception. This is a trade-off since the alternative would be to reraise the exception, which sadly destroys the backtrace.

val printf : Fmt.fmt io -> unit