By now, you might want to learn how to take the F# code we have been writing in the FSI window and convert it into actual F# programs. But in reality, every code snippet you have seen so far has been a full program!
Most other languages, like C#, require an explicit program entry point, often called a main method. Yet our F# programs so far haven’t declared any special markup indicating where the program should begin. In F#, for single-file applications, the contents of the code file are executed from top to bottom in order (without the need for declaring a specific main method).
For multifile projects, however, code needs to be divided into organization units called modules or namespaces.
All the code we have written so far has been in a module.
By default, F# puts all your code into an anonymous
module with the same name as the code file with the first
letter capitalized. So, if you have a value named
value1, and your code is in
file1.fs, you can refer to it by using the fully
You can explicitly name your code’s module by using the
module keyword at the top of a code file.
After that point, every value, function, or type defined will belong
to that module:
module Alpha// To refer to this value outside the module // use:
Alpha.xlet x = 1
Files can contain nested modules as well. To declare a
nested module, use the
followed by the name of your module and an equals sign
=. Nested ...