F# defining/using a type/module in another file in the same project
Solution 1
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
Solution 2
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)
Solution 3
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>
Solution 4
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.
Related videos on Youtube
JaredPar
Developer at Microsoft working on a language and operating system incubation project. Sites VsVim - VsVim on Visual Studio Gallery Blog - http://blog.paranoidcoding.com/ Twitter - http://twitter.com/jaredpar Linked In - http://www.linkedin.com/in/jaredpar Google+ - +JaredParsons Email: [email protected]
Updated on April 29, 2020Comments
-
JaredPar almost 4 years
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
-
Aisah Hamzah over 8 yearsAs 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.
-
-
JaredPar over 15 yearsPerfect! extra characters added to satifsy comment restrictions.
-
Ed Ayers almost 13 yearsThis 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
-
MEMark over 10 yearsI'm new to F#. What if I do have a circular dependency? Is this not possible in at all?
-
Goswin Rothenthal over 10 years@MEMark use the "and" keyword when you really need such types.
-
Aisah Hamzah over 8 yearsOr 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.
-
jps over 7 yearsJust 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
-
Aisah Hamzah over 7 years@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.
-
Aisah Hamzah over 7 yearsI believe these key bindings are only available with F# PowerTools installed (but most F# users install them anyway).
-
runeks about 5 years"What order are the files in the project?" what does this mean? All the files are in the same folder.
-
Scott Hutchinson almost 5 yearsThe 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.