The entry point to an F# application is declared using the attribute [<EntryPoint>]. For example, the default code when creating an F# application looks like
[<EntryPoint>] let main argv = printfn "%A" argv 0 // return an integer exit code
This declares that the function “main” is the entry point into the application.
This is fine until you start adding modules (new source code files in F#). So if we now add a new item (F# source file) to an F# application you’ll see an error such as this
Files in libraries or multiple-file applications must begin with a namespace or module declaration, e.g. ‘namespace SomeNamespace.SubNamespace’ or ‘module SomeNamespace.SomeModule’. Only the last source file of an application may omit such a declaration.
To fix this we need to do two things. The first is that by default the new module simple gets created with the following (obviously the module name will be the same as the filename you supplied it with)
module MyModule
as the error suggests we need to create a namespace for the new module, so for example
namespace Samples.One module Samples = let helloWorld = printfn "Hello World"
However this only solves part of the problem – the namespace issue.
The next thing we need to do is rather strange to me (maybe it’s my C++ background). But the [<EntryPoint>] file needs to be the last source code file in the project.
To make this happen, right mouse click on the Program.fs file (or whatever the name of your[<EntryPoint>] file is and using the Move Down and/or Move Up menu items, move the position of the file in the project to be the last source code file (note: it needn’t be the last actual file just the last source code file).
Note: Basically the order of the source code files is the order they’re compiled. So ordering of the files in important in F#.