How to put module into the right namespace when they are in directories?

Anamespace/Mod1.fs

namespace Anamespace
module Mod1

Program.fs

open Anamespace

It fails to compile and tells

/Users/jackalcooper/fsharp/Feetch/Feetch/Program.fs(1,1): Error FS0222: 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. (FS0222) (Feetch)

at the open expression in Program.fs

F# does not care whether your files are in directories or not but it expects all of them to be listed, in compilation order, in your project file. Make sure your files are listed as is:

<ItemGroup>
    <Compile Include="Anamespace/Mod1.fs" />
    <Compile Include="Program.fs" />
</ItemGroup>

Reversing the file order would cause the exact problem you described.

I’m sorry I’m new to F#. What exactly is in your project file? I’m using VS for Mac.

You should have a <project-name>.fsproj file in the root folder of your project, in there you should list the files you want to compile as part of your project but they have to come in the right order.

I see. It works now. Thank you!