hubFS: THE place for F#

. . . are you on The Hub?
Welcome to hubFS: THE place for F# Sign in | Join | Help
in Search

Referencing an F# module in VS2008 F# Project

Last post 01-31-2009, 0:29 by brianmcn. 6 replies.
Sort Posts: Previous Next
  •  01-30-2009, 4:23 8766

    Referencing an F# module in VS2008 F# Project

    Assume that I have an F# module called Fred, defined in file fred.fs

    How do I reference it in my F# project such that in file harry.fs I can say open Fred and everything is hunki dori?

    I have no problem with syntax, per se, and everything works fine in F# Interactive. My problem is with doing it in VS such that the syntax highlighting and type checking environment (let alone the compiler) doesn't barf on usages of functions defined in module Fred when they appear in harry.fs

    Can I reference a module from inside the same project? Or must it be built in another project and I can only reference resultant DLL from inside file harry's project?

    One way or the other, I'd greatly appreciate idiot-proof instructions for sorting this out in VS2008. Most of the online docs and info in various books seems to relate more to F# scripting. I am interested in compiling stuff.

    Many Thanks!

  •  01-30-2009, 5:55 8768 in reply to 8766

    Re: Referencing an F# module in VS2008 F# Project

    If my understanding is right, you have problems with file order. In VS(actually F# integration) order of the files does matter. Means that you cannot not have your harry.fs after fred.fs. To change file order jsut open *.fsproj file with notepad and find following:

    <ItemGroup>
        <Compile Include="harry.fs" />
        <Compile Include="fred.fs" />
    </ItemGroup>

    Ajust the order of the files from top to bottom.

  •  01-30-2009, 6:15 8769 in reply to 8768

    Re: Referencing an F# module in VS2008 F# Project

    Thanks for that tip!

    I've also stumbled across a kind of solution of the 'filename = module name' variety.... this lets me define and open a module from within the same project and I've got this working OK.

    But...

    I'm wondering also, however, how to reference an F# module from another project / DLL?
  •  01-30-2009, 6:57 8771 in reply to 8769

    Re: Referencing an F# module in VS2008 F# Project

    kinch:
    Thanks for that tip! I've also stumbled across a kind of solution of the 'filename = module name' variety.... this lets me define and open a module from within the same project and I've got this working OK.

    Yah, this is another feature, you also can get rid of the autogenerated module names by using namespaces.

    kinch:
    But... I'm wondering also, however, how to reference an F# module from another project / DLL?

    With regular "Add Reference..." menu. No magic here.

     

  •  01-30-2009, 9:10 8774 in reply to 8771

    Re: Referencing an F# module in VS2008 F# Project

    See also

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

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

    When I can find the time, I want to write another one about namespaces, filename-as-implicit-module, file order, etc.

  •  01-30-2009, 20:40 8783 in reply to 8774

    Re: Referencing an F# module in VS2008 F# Project

    Thanks! It really is that simple.

    I'm pretty sure I've seen

    Module Blah =

    as well as plain

    Module Blah

    in my travels. I realise that F# is a moving target and I'm going to see deprecated usages in books and blogs from time to time. Is this one of these cases?
  •  01-31-2009, 0:29 8784 in reply to 8783

    Re: Referencing an F# module in VS2008 F# Project

    Nope; they're both allowed and mean different things.  I think the one with the '=' is just defining a module nested in whatever outer construct you happen to be in whereas module-sans-equals is a way for the whole file to go in a module with a name other than the filename.  And an alternative to both is to start a file with a namespace, in which case it's a set of namespace fragments.  I don't even know it all offhand, which is why I need to experiment and read the spec and blog it.  :)  And there are still little holes in the language, like the inability to define a type in the global namespace.
View as RSS news feed in XML
Powered by Community Server, by Telligent Systems