Im puzzled
let test = "aString"
let callMe =
printfn test
Why isn’t this working? Throws below error at compile time:
The type ‘string’ is not compatible with the type ‘Printf.TextWriterFormat<‘a>’
This works fine:
printfn "aString"
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.
That’s because the
formatparameter is not actually astring. It’sTextWriterFormat<'T>and the F# compiler converts the string format into that type. But it doesn’t work onstringvariables, because the compiler can’t convert thestringtoTextWriterFormat<'T>at runtime.If you want to print the content of the variable, you shouldn’t even try to use
printfnthis way, because the variable could contain format specifications.You can either use the
%sformat:Or use the .Net
Console.WriteLine():Don’t forget to add
open Systemat the top of the file if you want to use theConsoleclass.