F Sharp for Beginners: Modules in F#

Let's learn about the Modules in F#. All the code you write in F Sharp is, by default, in a MODULE, regardless of whether you explicitly define a module or not.

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
 
 
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

  • 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)

Creating a Module
 
A Module name can explicitly be given by using the keyword "Module."
 
 
Now if you want to access the variable myNumber in some other module then you can access it like below:
 
 
Creating Nested Modules
 
You can create nested modules by using an equal to (=) sign with the module name.
 
 
In the above code, we have defined nested modules. You can access the myNumber1 variable like below:
 
 
In another module, you will find inellisense also working:
 
 
This was all about Modules in F#.
 
I hope this post was useful. Thanks for reading