在 Visual Studio 2012 中使用 F#,此代码编译:
let ``foo.bar`` = 5
但是这段代码没有:
type ``foo.bar`` = class end
Invalid namespace, module, type or union case name
根据F# 语言规范的第 3.4 节:
Any sequence of characters that is enclosed in double-backtick marks (````),
excluding newlines, tabs, and double-backtick pairs themselves, is treated
as an identifier.
token ident =
| ident-text
| `` [^ '\n' '\r' '\t']+ | [^ '\n' '\r' '\t'] ``
第 5 节将类型定义为:
type :=
( type )
type -> type -- function type
type * ... * type -- tuple type
typar -- variable type
long-ident -- named type, such as int
long-ident<types> -- named type, such as list<int>
long-ident< > -- named type, such as IEnumerable< >
type long-ident -- named type, such as int list
type[ , ... , ] -- array type
type lazy -- lazy type
type typar-defns -- type with constraints
typar :> type -- variable type with subtype constraint
#type -- anonymous type with subtype constraint
...并且第 4.2 节将 long-ident 定义为:
long-ident := ident '.' ... '.' ident
据我从规范中可以看出,类型是用长标识命名的,长标识可以是标识。由于 idents 支持双反引号引用的标点符号,因此类型似乎也应该如此。
那么我是否误读了规范?或者这是一个编译器错误?