Core_kernel.PrintfThis module extends Base.Printf.
include module type of struct include Base.Printf endval ifprintf : 'a -> ('r, 'a, 'c, unit) format4 -> 'rSame as fprintf, but does not print anything. Useful for ignoring some material when conditionally printing.
val sprintf : ('r, unit, string) format -> 'rSame as fprintf, but instead of printing on an output channel, returns a string.
val bprintf : Caml.Buffer.t -> ('r, Caml.Buffer.t, unit) format -> 'rSame as fprintf, but instead of printing on an output channel, appends the formatted arguments to the given extensible buffer.
val ksprintf : (string -> 'a) -> ('r, unit, string, 'a) format4 -> 'rSame as sprintf, but instead of returning the string, passes it to the first argument.
val kbprintf : (Caml.Buffer.t -> 'a) -> Caml.Buffer.t -> ('r, Caml.Buffer.t, unit, 'a) format4 -> 'rSame as bprintf, but instead of returning immediately, passes the buffer, after printing, to its first argument.
These functions have a polymorphic return type, since they do not return. Naively, this doesn't mix well with variadic functions: if you define, say,
let f fmt = ksprintf (fun s -> failwith s) fmtthen you find that f "%d" : int -> 'a, as you'd expect, and f "%d" 7 : 'a. The problem with this is that 'a unifies with (say) int -> 'b, so f "%d" 7 4 is not a type error -- the 4 is simply ignored.
To mitigate this problem, these functions all take a final unit parameter. These rarely arise as formatting positional parameters (they can do with e.g. "%a", but not in a useful way) so they serve as an effective signpost for "end of formatting arguments".
val failwithf : ('r, unit, string, unit -> _) format4 -> 'rRaises Failure.
val invalid_argf : ('r, unit, string, unit -> _) format4 -> 'rRaises Invalid_arg.
val eprintf : ('a, Stdio.Out_channel.t, Base.unit) Base.format -> 'aval fprintf : Stdio.Out_channel.t -> ('a, Stdio.Out_channel.t, Base.unit) Base.format -> 'aval kfprintf : (Stdio.Out_channel.t -> 'a) -> Stdio.Out_channel.t -> ('b, Stdio.Out_channel.t, Base.unit, 'a) Base.format4 -> 'bval printf : ('a, Stdio.Out_channel.t, Base.unit) Base.format -> 'aval exitf : ('a, unit, string, unit -> 'b) format4 -> 'aprint to stderr; exit 1