Why has the statement “printfn” in F# different name in VS2010 object browser?
-
26-01-2021 - |
Pergunta
I had know the difference between F# library and .NET library when I called their functions. But when I saw the statement "printfn" in VS 2010 object browser, I saw only the "public static T PrintFormatLine(... format)" instead of "printfn".
Why has the statement "printfn" in F# library different name in VS2010 object browser?
How can I call functions in F# library, if there aren’t documents for the F# library, because the names in VS 2010 object browser are totally different?
Solução
The printfn
function in the F# core library is annotated with a special attribute CompiledName
that specifies the name of the function in a compiled form:
[<CompiledName("PrintFormatLine")>]
let printfn fp = ...
What is this good for? I think the motivation is that the FSharp.Core.dll
library should follow the usual .NET naming guidelines. However, F# naming guidelines are a bit different (lowercase names are allowed, etc.), so the attribute is used to make the library look more like ordinary .NET library.
I don't think this is something that users of F# would use themselves. If you're writing code that will be used from C#, write it in a C# friendly style and if you're writing code that will be used from F#, follow the F# naming guidelines.