Since I do research with F# (in particular, using F# interactive), I\'d like to have switchable \"print-when-in-debug\" function.
I can do
let dprint
You can use the kprintf function, which formats a string using the standard syntax, but then calls a (lambda) function you specify to print the formatted string.
For example, the following prints the string if debug is set and otherwise does nothing:
let myprintf fmt = Printf.kprintf (fun str ->
// Output the formatted string if 'debug', otherwise do nothing
if debug then printfn "%s" str) fmt