Dooesn't let private x = 1" work"

I agree - I'm not to hot on interface files. So far I haven't found the need for them, but I haven't made any big libraries to share either.

By on 9/7/2009 11:30 AM ()

> Dooesn't "let private x = 1" work"?

Sure, it works - but the issue is if you have N items than are private, and N/10 items that are public, it would be nice to reverse the default visibility.

Ok - so, it looks like while "private module" is a syntax error, "module private" does work, and effects the visibility of the entire module - this behavior (if not the word order...) is more obvious than my suggestion of changing the visibility of items *in* the module. (And we definately don't want the syntactic analog of "const int* const"...)

So it looks as if one way to do this w/o FSI files is to define a private, inner module and reference it from the top-level.

For example:

1
2
3
4
5
module MyPublic

module private Privs = 
.         let P = 42
let Pub1 = (float Privs.P) / 3.14

AFAIKT though, there's no way to Open the inner module and inject the scope into the outer module for its use, so you need to referene the inner module explicity as above.

So some additional encapsulation solves this problem (takes a little more work) but it seems a reasonable alternative - if not a little *too* clean for my purposes at the moment :)

By on 9/7/2009 2:55 PM ()

Staying with a single file approach, you can use the AutoOpen attribute to give access to your private module:

1
2
3
4
5
6
7
8
9
10
11
12
13
.namespace Container

.

. . [AutoOpen] // should use square-brackets followed by angle-brackets

. . module private Privs =

. . .  let P = 42  

. . module MyPublic =

. . .  let Pub1 = (float P) / 3.14

I tend to follow this approach with an internal-only namespace relevant to the module and the use of "module internal" rather than "module private" as this has less impact on other parts of the same assembly.

The AutoOpen attribute without arguments ensures that the module's members are visible when the namespace is open but not otherwise.

I am not sure whether AutoOpen works if you have nested modules which is why I have separated them.

By on 9/11/2009 8:53 AM ()
IntelliFactory Offices Copyright (c) 2011-2012 IntelliFactory. All rights reserved.
Home | Products | Consulting | Trainings | Blogs | Jobs | Contact Us | Terms of Use | Privacy Policy | Cookie Policy
Built with WebSharper