F#:双引号值名称与函数名称冲突?

F#: Double backticked value names clash with function names?

2015 年 Visual Studio:

let myFunction (``string`` : string) =
    "\"Quoted string\"" |> (Regex "\"[^\"]*\"").Match |> string

let myOtherFunction (str : string) =
    "\"Quoted string\"" |> (Regex "\"[^\"]*\"").Match |> string

第一个函数生成编译器错误,string 函数用红色下划线标出。 ("This expression was expected to have type Match -> 'a but here has type string")

第二个功能没问题。

这是设计使然吗?

原因是,你的参数和最后的调用是一回事。双反引号用于转义名称,它们不是名称的一部分

所以在您的情况下,这意味着 ``string``string 是完全相同的东西,您正试图通过管道输入您的字符串参数。是的,这完全是设计使然。

C# 等效项是 @-escaped 名称,例如 @hellohello 会发生冲突。