Format string experimentations
Find a file
2021-07-19 11:27:41 +02:00
example Fix interpolation example 2021-07-19 11:27:41 +02:00
ppx (Last?) rename to ffmt 2021-07-19 10:35:43 +02:00
src last renaming 2021-07-19 10:33:34 +02:00
.gitignore gitignore 2018-02-02 16:04:45 +01:00
dune-project Transition to dune + more columns 2018-10-07 11:50:54 +02:00
ffmt-ppx-i.opam LICENSE and updated opam files 2021-07-19 11:14:28 +02:00
ffmt-ppx.opam LICENSE and updated opam files 2021-07-19 11:14:28 +02:00
ffmt.opam LICENSE and updated opam files 2021-07-19 11:14:28 +02:00
LICENSE LICENSE and updated opam files 2021-07-19 11:14:28 +02:00
Makefile Transition to dune + more columns 2018-10-07 11:50:54 +02:00
README.md Fix interpolation example 2021-07-19 11:27:41 +02:00

Ffmt is an experimental reimplementation of the OCaml format strings and Format module using standard features of OCaml.

Format strings are thus implemented using a ppx and GADTs.

The end result correctly looks like this:

let stdout =
    stdout
    |> fp {%fmt|Hello %s! |} ["Earth"]
    |> fp {%fmt|%d + %g = %s|} [1;2.;"3"]

Another interesting features of Ffmt is that it decouples the format string interpreter, the formatting engine and the backends. As an illustration, Ffmt comes with a string interpolation-inspired interpreter for format string.

let stdout =
    let earth = string "Earth" in
    let one = int 1 in
    stdout
    |> fpi {%fmt|Hello %{earth}! |}
    |> fpi {%fmt|%{one} + %{float 2.} = %{string "3"}|}