F# Projects – Order Does Matter

It’s common to run into a few simple problems when learning a new programming language. One such problem that I ran into with F# was resolving dependencies within projects.

With the September F# CTP (version 1.9.6.2), it’s pretty easy to handle dependencies on external projects since it is done as it is in C# with the "Add Reference…" context menu item. Dependencies between .fs files within a project behave a bit differently, though. As it turns out, the order that the files appear in the project determines the order that they are compiled in.

For example, lets say that I have the following two files:

SomeLibrary.fs

#light

namespace SomeLibrary

    type SomeType = { foo : int }

Dependent.fs

#light

open SomeLibrary

let deFoo (x:SomeType) = 
    x.foo

If I place Dependent.fs above SomeLibrary.fs in the project as shown below, I get a lovely compile error telling me that "The namespace or module ‘SomeLibrary’ is not defined".

image

However, once you switch the order using the "Move Up" or "Move Down" context menu actions, everything works as expected.

image

This entry was posted in F#. Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

2 Comments

  1. Mario P
    Posted March 4, 2009 at 7:46 pm | Permalink

    I have the same problem, but I have a WebSite Project.

    How I can define the order of compilation for the files in App_Code ?

  2. cmarinos
    Posted March 9, 2009 at 2:13 pm | Permalink

    Mario-

    I don’t have very much ASP.NET experience, but in a standard F# project, compilation order seems to be based on the order of the nodes in the .fsproj file.

    I hope that helps a little. Either way, let me know what the solution was if you figure it out.

    -Chris

Post a Comment

Your email is never published nor shared. Required fields are marked *

You may use these HTML tags and attributes <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

*
*