package core

  1. Overview
  2. Docs
Legend:
Library
Module
Module type
Parameter
Class
Class type
val ifprintf : 'a -> ('r, 'a, 'c, unit) Stdlib.format4 -> 'r
val sprintf : ('r, unit, string) Stdlib.format -> 'r
val bprintf : Base__.Import0.Caml.Buffer.t -> ('r, Base__.Import0.Caml.Buffer.t, unit) Stdlib.format -> 'r
val ksprintf : (string -> 'a) -> ('r, unit, string, 'a) Stdlib.format4 -> 'r
val kbprintf : (Base__.Import0.Caml.Buffer.t -> 'a) -> Base__.Import0.Caml.Buffer.t -> ('r, Base__.Import0.Caml.Buffer.t, unit, 'a) Stdlib.format4 -> 'r
val failwithf : ('r, unit, string, unit -> 'a) Stdlib.format4 -> 'r
val invalid_argf : ('r, unit, string, unit -> 'a) Stdlib.format4 -> 'r
val eprintf : ('a, Stdlib.out_channel, Base.Unit.t) Stdlib.format -> 'a
val fprintf : Stdlib.out_channel -> ('a, Stdlib.out_channel, Base.Unit.t) Stdlib.format -> 'a
val kfprintf : (Stdlib.out_channel -> 'a) -> Stdlib.out_channel -> ('b, Stdlib.out_channel, Base.Unit.t, 'a) Stdlib.format4 -> 'b
val printf : ('a, Stdlib.out_channel, Base.Unit.t) Stdlib.format -> 'a
val exitf : ('a, Base.Unit.t, Base.String.t, Base.Unit.t -> _) Stdlib.format4 -> 'a

print to stderr; exit 1

type printf = {
  1. printf : 'a. ('a, Stdlib.Buffer.t, Base.Unit.t) Stdlib.format -> 'a;
}
val collect_to_string : (printf -> Base.Unit.t) -> Base.String.t

collect_to_string (fun { printf } -> ...) lets you easily convert code that was printing to stdout into code that produces a string.

For example, this original code...

printf "hello ";
(* long computation *)
printf "%s%c" "world" '!'

... can be wrapped like so.

Printf.collect_to_string (fun { printf } ->
  printf "hello ";
  (* long computation *)
  printf "%s%c" "world" '!')

The above is easier than manually editing many lines of the original:

let hello = sprintf "hello " in
(* long computation *)
let world = sprintf "%s%c" "world" '!' in
hello ^ world
OCaml

Innovation. Community. Security.