开发者

F# treating internal module as private

Any ideas why the following doesn’t compile?

On the last line it tells me that Module1 is not defined. If I remove the “internal” from M开发者_StackOverflow社区odule1 it works fine.

I've got two code files and Module1.fs is above Module2.fs in the project.

Module1.fs

module internal Module1

let sample =
    5 + 4

Module2.fs

module Module2

let sample2 =
    3 + Module1.sample


You'll need to give your modules a namespace so the internal module is visible to later ones.

let module internal MyNamespace.Module1
let module MyNamespace.Module2


Compiler bug

While the answers here are workarounds, this behavior is still a compiler bug. Reading the docs and Don Syme's Expert F#, there is no point that says that types in internal modules will be accessible only if you also use namespaces.

Considering the code the compiler emits I would not see a difficulty to make types inside internal modules visible inside the assembly.

Edit: Having filed this behavior to @fsbugs, the master himself, Don Syme, soon confirmed this being a bug. I added a workitem for this case:

https://visualfsharp.codeplex.com/workitem/29


this should be a namespace problem. Just add namespace definitions on top of both your files (the same namespace!) like this:

namespace MyNamespace

module internal Module1 =

let sample = 5+4

and

namespace MyNamespace

module Module2 =

let sample2 = 3 + Module1.sample
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜