I have a function that takes a string and sends it to a terminal:
Print: string -> unit
it is passed to several modules that do this, to simplify the syntax
// printing
let print = settings.Print
and then it’s used like that:
print "hello"
print (sprintf "the time is %A" DateTime.UtcNow)
my question is: Can I make two functions, with the same name but two signatures, so I could use it to either print a string, or a sprintf, then print the string.
for example:
print "hello"
print "the time is %A" DateTime.UtcNow
Is this possible? the goal is to simplify the syntax as a lot of code is peppered with info being sent to the terminal (which is currently a Telegram channel)
2
Answers
You can use the same signature as sprintf:
and you can use it as you want:
You can use
kprintf
for this:There are some examples here and here.
I couldn’t find
kprintf
documentation, so I’m not sure that this usage is correct, but it produces the correct result for me. Another possible candidate isksprintf
, which also produces the same result.