Ppx_deriving implementation for pretty printing sets & maps

The containers stdlib extension makes this almost effortless:

open Containers

module Signals = Set.Make(Char)
let () = Format.printf "my set: %a" (Signals.pp Char.pp) @@ Signals.of_list ['a']

“Almost”, because the pp on Set, Map, etc needs to be parameterized by the value in question; but you can prefill that to make e.g. nested/recursive usage fit together nicely:

module Signals = struct
  module M = Set.Make (Char)
  include M

  let pp = M.pp Char.pp
end

let () =
  Format.printf "my set: %a" Signals.pp @@ Signals.of_list ['a']
2 Likes