Skip to content

@t0yv0 /DPrint.fs
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
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
Something went wrong with that request. Please try again.