1

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?

4

1 回答 1

6

F# 核心库中的printfn函数使用特殊属性进行注释,该属性CompiledName以编译形式指定函数的名称:

[<CompiledName("PrintFormatLine")>]
let printfn fp = ...

这有什么好处?我认为动机是该FSharp.Core.dll库应该遵循通常的 .NET 命名准则。但是,F# 命名准则有点不同(允许使用小写名称等),因此使用该属性使库看起来更像普通的 .NET 库。

我不认为这是 F# 的用户自己会使用的东西。如果您正在编写将从 C# 使用的代码,请以 C# 友好的风格编写它;如果您正在编写将从 F# 使用的代码,请遵循 F# 命名准则。

于 2011-09-23T01:39:34.013 回答