SIGN UP MEMBER LOGIN:    
ARTICLE

F Sharp for Beginners: Modules in F#

Posted by Dhananjay Kumar Articles | F# October 02, 2011
Let's learn about the Modules in F#.
Reader Level:

All the code you write in F Sharp is, by default, in a MODULE, regardless of whether you explicitly define a module or not.

Anonymous Module

Modules in fsharp

Anonymous modules have the same name as the file name with the first letter in upper case.

Let us say,

  • You are writing code inside a file called myfile.fs
  • You have explicitly not given a module name.
  • Inside the file myfile.fs, you have code like below

    Modules in Fsharp

  • By default, the module for the above code would be Myfile (same as the file name of the code with first letter in upper case)

    F#  Modules

Creating a Module

A Module name can e
xplicitly be given by using the keyword "Module."

Fsharp modules 

Now if you want to access the variable myNumber in some other module then you can access it like below:

F-sharp modules

Creating Nested Modules

You can create nested modules by using an equal to (=) sign with the module name.

Modules in f-sharp

In the above code, we have defined nested modules. You can access the myNumber1 variable like below:

Modules fsharp

In another module, you will find inellisense also working:

Modules

This was all about Modules in F sharp.

I hope this post was useful. Thanks for reading

List of articles of F Sharp beginner series

If you find my posts useful you may like to follow me on twitter http://twitter.com/debug_mode or may like Facebook page of my blog http://www.facebook.com/DebugMode. Net If you want to see post on a particular topic please do write on FB page or tweet me about that, I would love to help you.

[twitter-follow screen_name='debug_mode' show_count='yes']

Login to add your contents and source code to this article
share this article :
post comment
 
6 Months Free & No Setup Fees ASP.NET Hosting!
Become a Sponsor
PREMIUM SPONSORS
  • Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
    Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
Become a Sponsor