为什么 F# 存在模块名称部分重叠的问题?
Why is F# having a problem with partially overlapping module names?
这个总是让我着迷,我无法理解 F# 编译器在这里遇到的问题。
我有两个模块的两个文件。
A.fs:
module A
//rest of the module goes here
B.fs
module A.B
//rest of the module goes here
当我构建这个项目时,我得到:
A.fs(1, 8): [FS0247] A namespace and a module named 'A' both occur in two parts of this assembly
为什么?除了 Program.fs,项目中没有其他内容。我是否错误地假设我可以将模块分解为多个文件以控制事情,同时使用命名方案之类的命名空间? (显然编译器是这么认为的)。
我想了解编译器在这里遇到的问题,以及为什么我会看到一个引用命名空间的错误,即使我的代码中没有命名空间声明。
这是这个问题的答案,以防万一有人遇到同样的错误并在这里搜索他们的方式。
the modules documentation 中的这一点解释了正在发生的事情:
In the syntax for the top-level module declaration, the optional
qualified-namespace is the sequence of nested namespace names that
contains the module.
通过将模块声明为 A.B
我实际上是在按照上述描述在命名空间 A
中声明模块 B
。所以我最终得到了一个名为 A
的模块,因为
module A
和一个命名空间 A
由于 module A.B
编译器告诉我我现在在这个程序集中有一个模块和一个名为 A
的命名空间。
我会更改此答案或取消接受,以防我错了。
这个总是让我着迷,我无法理解 F# 编译器在这里遇到的问题。
我有两个模块的两个文件。
A.fs:
module A
//rest of the module goes here
B.fs
module A.B
//rest of the module goes here
当我构建这个项目时,我得到:
A.fs(1, 8): [FS0247] A namespace and a module named 'A' both occur in two parts of this assembly
为什么?除了 Program.fs,项目中没有其他内容。我是否错误地假设我可以将模块分解为多个文件以控制事情,同时使用命名方案之类的命名空间? (显然编译器是这么认为的)。
我想了解编译器在这里遇到的问题,以及为什么我会看到一个引用命名空间的错误,即使我的代码中没有命名空间声明。
这是这个问题的答案,以防万一有人遇到同样的错误并在这里搜索他们的方式。
the modules documentation 中的这一点解释了正在发生的事情:
In the syntax for the top-level module declaration, the optional qualified-namespace is the sequence of nested namespace names that contains the module.
通过将模块声明为 A.B
我实际上是在按照上述描述在命名空间 A
中声明模块 B
。所以我最终得到了一个名为 A
的模块,因为
module A
和一个命名空间 A
由于 module A.B
编译器告诉我我现在在这个程序集中有一个模块和一个名为 A
的命名空间。
我会更改此答案或取消接受,以防我错了。