Como faço para usar uma variável como a seqüência de formatação com Sprintf?
Eu me sinto como um noob total por ter que perguntar isso, mas isso me deixou perplexo.
Eu defino uma string de formato como esta:
let fs = "This is my format test %s"
Então eu tento usá-lo assim:
let s = sprintf fs "testing"
Quando faço isso, recebo este erro:
//stdin(26,17): error FS0001: The type 'string' is not compatible with the type 'Printf.StringFormat<('a -> 'b)>'
Então eu tentei isso:
let s = sprintf (Printf.StringFormat fs) "test"
a que o REPL respondeu:
//stdin(28,18): error FS1124: Multiple types exist called 'StringFormat', taking different numbers of generic parameters. Provide a type instantiation to disambiguate the type resolution, e.g. 'StringFormat<_>'.
Então eu tentei isso:
let s = sprintf (Printf.StringFormat<string> fs) "test"
E eu entendo isso:
//stdin(29,18): error FS0001: The type ''a -> 'b' does not match the type 'string'
Eu estou sentindo falta de algo dolorosamente óbvio? Isso está usando o F # 3.0 no Mac da Xamarin Studio F # Interactive Window.