Skip to content

Instantly share code, notes, and snippets.

@t0yv0 t0yv0/DPrint.fs
Created Jul 19, 2012

What would you like to do?
let rec mkKn (ty: System.Type) =
if Reflection.FSharpType.IsFunction(ty) then
let _, ran = Reflection.FSharpType.GetFunctionElements(ty)
// NOTICE: do not delay `mkKn` invocation until runtime
let f = mkKn ran
Reflection.FSharpValue.MakeFunction(ty, fun _ -> f)
box ()
let dprint (v: bool) (fmt: Printf.TextWriterFormat<'a>) : 'a =
if v then
printfn fmt
unbox<'a> (mkKn typeof<'a>)
type Format<'T> private () =
static let instance : 'T =
unbox (mkKn typeof<'T>)
static member Instance = instance
let dprint2 verbose args =
if verbose then
printfn args
for i in 0 .. 10000 do
dprint false "%i" i // 1 sec
for i in 0 .. 10000 do
dprint2 false "%i" i // 0.001 sec
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.