Module Fmt.Lit

Formatting OCaml literal values.

val unit : unit t

unit formats unit literals.

val bool : bool t

bool formats bool literals.

val int : int t

int formats int literals. Warning. Values formatted on a 64-bit platform may not parse on 32-bit platforms.

val int32 : int32 t

int32 formats signed int32 literals.

val uint32 : int32 t

uint32 formats unsigned int32 literals (i.e. as hexadecimal).

val int64 : int64 t

int64 formats signed int64 literals.

val uint64 : int64 t

uint64 formats unsigned int64 literals (i.e. as hexadecimal).

val nativeint : nativeint t

nativeint formats signed nativeint literals.

val nativeuint : nativeint t

nativeuint formats unsigned nativeint literals (i.e. as hexadecimal).

val float : float t

float formats float literals (using "%F").

val hex_float : float t

float formats hex float literals (using "%#F").

Chars and strings

FIXME. Can we make the string combinators multi line ?

val char : char t

char formats char literals as follows:

  • Char.Ascii.is_print except single quote and slash are printed verbatim.
  • Characters '\'', '\\', '\n', '\r' and '\t' are printed just as written here.
  • Other charactres use hex escapes '\xhh'.
val ascii_string : string t

ascii_string formats string literals using char, except that double quotes are escaped and single quotes are not.

val string : string t

string formats string literals. Assumes an UTF-8 encoded string but escapes:

  • Double quotes.
  • C0 control characters (U+0000-U+001F)
  • C1 control characters (U+0080-U+009F)
  • Line separator (U+2028) and paragraph separator (U+2029).
  • UTF-8 decode errors by hex escapes \xhh.
val binary_string : string t

binary_string formats binary string literals. All characters are formatted using \xhh escapes.

Parametric types

Note. Depending on what you print an enclosing parens may be due on the arguments.

val option : 'a t -> 'a option t

option formats option literals.

val either : left:'a t -> right:'b t -> ('a, 'b) Either.t t

either formats Either.t literals.

val result : ok:'a t -> error:'b t -> ('a, 'b) Stdlib.result t

result ~ok ~error formats result literals.

val list : 'a t -> 'a list t

list formats list literals.

val array : 'a t -> 'a array t

array formats array literals.

val pair : 'a t -> 'b t -> ('a * 'b) t

pair formats pair literals.

val t2 : 'a t -> 'b t -> ('a * 'b) t

t2 is pair.

val t3 : 'a t -> 'b t -> 'c t -> ('a * 'b * 'c) t

t3 formats triples.

val t4 : 'a t -> 'b t -> 'c t -> 'd t -> ('a * 'b * 'c * 'd) t

t4 formats quadruples.

val t5 : 'a t -> 'b t -> 'c t -> 'd t -> 'e t -> ('a * 'b * 'c * 'd * 'e) t

t5 formats quintuplets.

val t6 : 'a t -> 'b t -> 'c t -> 'd t -> 'e t -> 'f t -> ('a * 'b * 'c * 'd * 'e * 'f) t

t6 formats sextuplets.