My Technical Notes

Tuesday, 13 January 2015

F# - using Formatting Syntax

It is pretty simple to use the print formatting syntax in your own method signature:


let writefn fmt = Printf.ksprintf (fun s -> Debug.WriteLine(s)) fmt

Because the lambda is passing its input `s` to `Debug.WriteLine`, we can reduce the above code to:


let writefn fmt = Printf.ksprintf Debug.WriteLine fmt

Source: Printf and Formatting Debug Output in F#

No comments: