Created
July 19, 2012 16:49
-
-
Save t0yv0/3145242 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
else | |
box () | |
let dprint (v: bool) (fmt: Printf.TextWriterFormat<'a>) : 'a = | |
if v then | |
printfn fmt | |
else | |
unbox<'a> (mkKn typeof<'a>) | |
[<Sealed>] | |
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 | |
else | |
Format<_>.Instance | |
#time | |
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