F# defining/using a type/module in another file in the same project

前端 未结 5 1036
被撕碎了的回忆
被撕碎了的回忆 2020-12-05 22:34

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

相关标签:
5条回答
  • 2020-12-05 23:06

    What order are the files in the project? 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

    0 讨论(0)
  • 2020-12-05 23:06

    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>
    
    0 讨论(0)
  • 2020-12-05 23:07

    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".

    0 讨论(0)
  • 2020-12-05 23:09

    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.

    0 讨论(0)
  • 2020-12-05 23:12

    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)

    0 讨论(0)
提交回复
热议问题