Is it possible to have a polyvariadic type provider?

#1

Wondering if it’s possible to have a polyvariadic type provider. The user case I had in mind was to create a SprintfProvider that would be able to evaluate a sprintf-type function at compile time, assuming the arguments were also literals. Something like:

let [<Literal>] str1 = "one"
let [<Literal>] str2 = "two"

let [<Literal>] finalStr = sprintf<"%s and then %s", str1, str2>.Value

Is such a thing possible?

0 Likes

#2

I’m not sure about the variable inputs but apart from that a type provider would be a better way to implement sprintf. Probably this would have been the default implementation if type providers had been around for F# 1.0. You would get better performance and AOT compatiblity this way, and better language consistency.

0 Likes