Fmt library signatures and declarations

Hi there,
while trying to learn Ocaml I have come across a few things I couldn’t wrap my mind around so far.
In the source code of the library “Fmt”, I found these signatures in fmt.mli:

val prefix : unit t -> 'a t -> 'a t
val suffix : unit t -> 'a t -> 'a t 

which are both marked deprecated in the more recent versions.
Apparently both functions have 2 arguments.
However in the fmt.ml file I found these declarations

let prefix pp_p pp_v ppf v = pp_p ppf (); pp_v ppf v
let suffix pp_s pp_v ppf v = pp_v ppf v; pp_s ppf ()

It seems to me that these are functions of 4 arguments,
not 2 like the signatures suggest.
What am I missing here?

Also, in one of my own programs I have this bit of code:

let pp_header =
    Fmt.suffix Fmt.(const string " ") @@ Fmt.prefix now_fmt Logs_fmt.pp_header

This is giving me warnings/errors due to Fmt.suffix and prefix being deprecated
and telling me to use Fmt.(++) instead.
How would I rewrite the code using Fmt.(++) here?

Thanks for your replies!

The type 'a t is defined to be Format.formatter -> 'a -> unit, so the definition

let prefix pp_p pp_v ppf v = ...

should be understood as

let prefix pp_p pp_v = fun ppf v -> ...

where fun ppf v -> ... is the value of type 'a t.

Something like this:

let (++) = Fmt.(++)
let pp_header =
  Fmt.using ignore now_fmt ++ Logs_fmt.pp_header ++ Fmt.const Fmt.string " "

Cheers,
Nicolas

1 Like