Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 Module1 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
like image 754
Mark Pattison Avatar asked Sep 06 '11 15:09

Mark Pattison


3 Answers

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
like image 191
Daniel Avatar answered Oct 23 '22 19:10

Daniel


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

like image 27
citykid Avatar answered Oct 23 '22 18:10

citykid


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
like image 2
Random Dev Avatar answered Oct 23 '22 19:10

Random Dev