I am writing my first F# library
I am trying to use string.Format and it complains that no such function exists.
Is it not available or am I doing something wrong?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
If you want to avoid using the full name, you can use
openin F#:This should work in both F# interactive (enter the
openclause first) and in normal compiled applications. The key thing is that you must writeStringwith upper-caseS. This is becausestringin C# isn’t a usual type name – it is a keyword refering to theSystem.Stringtype.Alternatively, you could also take a look at the
sprintffunction. It is an F#-specific alternative toString.Formatwhich has some nice benefits – for example it is type checked:The compiler will check that the parameters (string and int) match the format specifiers (
%sfor string and%dfor integers). The function also works better in scenarios where you want to use partial function application:This will produce a list of strings containing “number 1”, “number 2” etc… If you wanted to do this using
String.Format, you’d have to explicitly write a lambda function.