Wie verwende ich eine Variable als Formatierungszeichenfolge mit Sprintf?

Ich fühle mich wie ein Noob, weil ich das fragen muss, aber es hat mich verblüfft.

Ich habe eine Formatzeichenfolge wie folgt festgelegt:

let fs = "This is my format test %s"

Dann versuche ich es so zu benutzen:

let s = sprintf fs "testing"

Wenn ich das tue, bekomme ich folgende Fehlermeldung:

//stdin(26,17): error FS0001: The type 'string' is not compatible with the type 'Printf.StringFormat<('a -> 'b)>'

Also habe ich dann folgendes probiert:

let s = sprintf (Printf.StringFormat fs) "test"

auf die die REPL geantwortet hat:

//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<_>'.

Also habe ich dann folgendes probiert:

let s = sprintf (Printf.StringFormat<string> fs) "test" 

Und ich verstehe:

//stdin(29,18): error FS0001: The type ''a -> 'b' does not match the type 'string'

Vermisse ich etwas schmerzlich offensichtliches? Dies verwendet F # 3.0 auf dem Mac im interaktiven Xamarin Studio-F # -Fenster.

Antworten auf die Frage(1)

Ihre Antwort auf die Frage