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

 

 FSharpOrder1

 

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

 

 FSharpOrder2

Published 18 December 2008 02:35 PM by cmarinos
Filed under:

Comments

# Mario P said on 04 March, 2009 02:46 PM

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 ?

# cmarinos said on 09 March, 2009 10:13 AM

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 <Compile Include> 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

Leave a Comment

(required) 
(required) 
(optional)
(required)