85

This will hopefully be an easy one. I have an F# project (latest F# CTP) with two files (Program.fs, Stack.fs). In Stack.fs I have a simple namespace and type definition

Stack.fs

namespace Col

type Stack= 
 ...

Now I try to include the namespace in Program.fs by declaring

open Col

This doesn't work and gives me the error "The namespace or module Col is not defined." Yet it's defined within the same project. I've got to be missing something obvious

1
  • 3
    As a tip: if you need to change the order of the files in Visual Studio, install F# PowerTools, and use Alt+Arrow in the solution explorer to move them around (or right-click). You can also move them to other folders, or create new folders etc.
    – Abel
    Dec 16, 2015 at 22:11

5 Answers 5

93

What order are the files in the .fsproj file? Stack.fs needs to come before Program.fs for Program.fs to be able to 'see' it.

See also the start of

http://lorgonblog.spaces.live.com/blog/cns!701679AD17B6D310!444.entry

and the end of

http://lorgonblog.spaces.live.com/blog/cns!701679AD17B6D310!347.entry

4
  • 1
    Perfect! extra characters added to satifsy comment restrictions.
    – JaredPar
    Oct 6, 2008 at 0:23
  • 1
    This one caught me out too, I would have thought that the F# compiler could just have a quick check in all the other files and look for the missing modules... seems simple enough
    – Ed Ayers
    Jul 19, 2011 at 9:26
  • "What order are the files in the project?" what does this mean? All the files are in the same folder.
    – runeks
    Mar 28, 2019 at 8:26
  • The order in which the files are listed in the .fsproj file is what matters. Visual Studio Solution Explorer should list them in that same order and provide context menu commands to move them up or down. Jul 7, 2019 at 17:51
46

I had the same problems, and you are right, the order of the files is taken in account by the compiler. Instead of the Remove and Add pattern, you can use the Move Up / Move Down items in the context menu associated to the .fs files. (Alt-Up and Alt-Down are the shortcut keys in most of the standard key-bindings)

1
  • I believe these key bindings are only available with F# PowerTools installed (but most F# users install them anyway).
    – Abel
    Oct 9, 2016 at 21:22
17

All of the above are correct, but how to do this in VS2013 is another question. I had to edit my .fsproj file manually, and set the files in exact order within an ItemGroup node. In this case it would look like this:

<ItemGroup>
    <Compile Include="Stack.fs" />
    <Compile Include="Program.fs" />
    <None Include="App.config" />
</ItemGroup>
3
  • Or you could've simply installed F# PowerTools, which allows you to move a file up or down, move them to a directory, or out of it, and much more. Will save you a lot of time.
    – Abel
    Dec 16, 2015 at 22:10
  • 2
    Just had this occur in VS2015 - moving files up or down wasn't fixing the issue - had to edit the .fsproj file manually. - Possible bug in F# PowerTools
    – jps
    Sep 15, 2016 at 19:45
  • 1
    @jps, yes, I noticed some bugs with PowerTools too, esp. when moving directories up/down (they end up at the bottom in fsproj, but appear higher in VS). Moving within one directory usually goes right (for me). Luckily you can now edit the fsproj directly within VS2015.
    – Abel
    Oct 9, 2016 at 21:20
1

I had the same issue and it was indeed the ordering of the files. However, the links above didn't describe how to fix it in Visual Studio 2008 F# 1.9.4.19.

If you open a module, make sure your source file comes after the dependency in the solution explorer. Just right click your source and select Remove. Then re-add it. This will make it appear at the bottom of the list. Hopefully you don't have circular dependencies.

2
  • 1
    I'm new to F#. What if I do have a circular dependency? Is this not possible in at all?
    – MEMark
    Oct 22, 2013 at 14:53
  • 1
    @MEMark use the "and" keyword when you really need such types. Nov 8, 2013 at 14:35
0

I'm using Visual Studio for Mac - 8.1.4 and i've noticed that some .fs files are not marked as "Compile". You can see this by Viewing Build Output and see if all your files are there and in the correct order.

I've had to manually make sure certain files are marked with "Compile", and have had to move them up and down manually until it "takes".

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.