I'm aware of other questions about modules and namespaces in F#, but they're not helping me right now.
I've got a project with
Utilities.fs
namespace Company.Project.Namespace
module Utilities =
//stuff here
Functions.fs
namespace Company.Project.Namespace
open Utilities
module Functions =
//stuff here
And I'm trying to test them in an fsx:
#load "Utilities.fs"
#load "Functions.fs"
which gives me error FS0039: The namespace or module 'Utilities' is not defined
when I try to send it to FSI with Alt-Enter
.
I've tried adding same namespace at the top of the script file, but it doesn't like that.
What's weird is that the background compiler doesn't shout at me.
This seems to work, but is it the right approch?
#load "Utilities.fs"
open Company.Project.Namespace
#load "Functions.fs"
Is there a 'reference' FSharp project somewhere, which contains examples of how to integrate all this stuff: namespaces, modules, classes, script files, tests etc.?
Best Answer
I'm not an expert with FSI, but some experimentation suggests that namespaces are only supported by
#load
declarations (not via typical interactions - sending a namespace declaration group to VFSI via Alt-Enter does not work), and that different interactions contribute different 'instances'. For example, with the code fileif I
#load
it more than once I get e.g.Note that it seems the FSI_0003.Foo.Bar shadowed the FSI_0002 version.
So I'm thinking the part of the F# spec that says
Does not interact with FSI, given FSI's limited understanding of namespaces. Specifically, I expect that the 'second #load' from your example opens e.g.
FSI_000N+1
's version of the namespace, whereas the prior code was inFSI_000N
. Which maybe-explains why the explicitopen
interaction fixes it; you bring the existing, unshadowedFSI_000N
stuff up to the top level before trying to (implicitly) reference it later.