package core_kernel

  1. Overview
  2. Docs
Legend:
Library
Module
Module type
Parameter
Class
Class type

This module extends Base.Printf.

include module type of struct include Base.Printf end
val ifprintf : 'a -> ('r, 'a, 'c, unit) Pervasives.format4 -> 'r
val sprintf : ('r, unit, string) Pervasives.format -> 'r
val bprintf : Base__.Import0.Caml.Buffer.t -> ('r, Base__.Import0.Caml.Buffer.t, unit) Pervasives.format -> 'r
val ksprintf : (string -> 'a) -> ('r, unit, string, 'a) Pervasives.format4 -> 'r
val kbprintf : (Base__.Import0.Caml.Buffer.t -> 'a) -> Base__.Import0.Caml.Buffer.t -> ('r, Base__.Import0.Caml.Buffer.t, unit, 'a) Pervasives.format4 -> 'r
Formatting error and exit functions

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) fmt

then 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 -> _) Pervasives.format4 -> 'r

Raises Failure.

val invalid_argf : ('r, unit, string, unit -> _) Pervasives.format4 -> 'r

Raises Invalid_arg.

val eprintf : ('a, Stdio.Out_channel.t, Base.unit) Base.format -> 'a
val printf : ('a, Stdio.Out_channel.t, Base.unit) Base.format -> 'a
val exitf : ('a, unit, string, unit -> 'b) Pervasives.format4 -> 'a

print to stderr; exit 1

OCaml

Innovation. Community. Security.