1
votes

Just trying to structure an F# library. So far it "appears" that:

  • I can only reference the C# library from a .fs source file,

  • and .fs source files are not available to .fsx script files.

Are any of these statements are correct? The examples I read say just use an open, but that only works from a .fs file.

Is there a version of

#r "System.Drawing.dll"

for script files used via f# interactive (fsi) in the same project?

Also, I find the syntax difference between top level modules and lower modules a little strange. Top me it's weird that the top level doesn't have an equals.

module Utilities

    module et =

Why not be consistent and have "module moduleName = " for everything?

1
I think im not understanding you correctly, but are you aware that, in VS, file order matters for F#? stackoverflow.com/questions/2908473/… - fableal

1 Answers

5
votes

It is important to note that "References" in Visual Studio in F# only apply to the current project. If you're working in a script file, it does not see the libraries referenced by the project.

To reference a library in a script file (e.g. Script.fsx), you can write (you can use both absolute paths and relative paths):

#r @"C:\<path_to_library>\library.dll"

If you want to load a file that is not a script (e.g. Library.fs) from a script file you can use:

#load "Library.fs"

The fs file itself cannot contain directives like #r, so if the file is using some library that needs to be referenced, you need to have an #r directive in the main script file (to reference the library before loading the source file).

As for the module inconsistency, the main reason is that when you use module Foo or namespace Foo at the top-level, you do not need to indent the rest of the file:

module Foo

let bar = 10
module Sub = 
  let bar = 12