I use pf as an abbreviation of printfn
let pf = printfn
// signature:
val pf : (Printf.TextWriterFormat<'a> -> 'a)
Can we change pf so that it is a noop and does not output anything? I tried things like
let pf<'a> (x : (Printf.TextWriterFormat<'a> -> 'a)) = ()
// signature:
val pf : (Printf.TextWriterFormat<'a> -> 'a)
How about:
> let noprintf f = Printf.ksprintf (fun _ -> ()) f;;
val noprintf : f:Printf.StringFormat<'a,unit> -> 'a
> noprintf "Hello, %s!" "world";;
val it : unit = ()
>
Here is a simple solution
let pf fstring =
if false then
printfn fstring
else
fun _ -> Operators.Unchecked.defaultof<'a>;;
Note: this does have some problems and wont work in all cases - see comments
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.