How to avoid line splitting in Format.printf?


#1

Can someone please help me to get rid of the automatic line splitting due to Format.printf for the following piece of code. Using set_margin only seems to work up to a certain limit but doesn’t help for very very long lines.

let () = Map.iteri file_types ~f:(fun ~key:name ~data ->
    Format.printf "%s %s %a@." filename name Pprintast.core_type data
)

The full code is here:

I’ve tried to use Printf.printf, but the interface is not compatible:

Error: This expression has type Format.formatter -> core_type -> unit
       but an expression was expected of type out_channel -> 'a -> unit
       Type Format.formatter is not compatible with type out_channel

#2

What is the issue exactly? Did you have an example of unintended line break? Did you remember to set max_indent to margin - 10 after increasing the margin?


#3

Thanks @octachron! I didn’t know about set_max_indent, that solved the problem.