Abel
Abel

Reputation: 57159

What does "namespace FSI_00XX" mean in FSharp Interactive?

Each time I load an FSX script file (or any other file for that matter) in FSharp Interactive in Visual Studio 2015, it prints a message:

> #load "D:\Projects\Tests.fsx";;
[Loading D:\Projects\Tests.fsx]

namespace FSI_0055

It doesn't matter whether the FSX is empty, has one or more types or modules in it. The result is always the loading message (clear enough) and then the namespace FSI_00XX message, where XX is an incremental number. I.e., if I run the above command again (with or without changes to the file) it shows this:

> #load "D:\Projects\Tests.fsx";;
[Loading D:\Projects\Tests.fsx]

namespace FSI_0056

It looks like an error, but clearly it isn't. My guess is, it is an implicit namespace, and the current namespace will be set to the latest. Does it also mean that I can refer to the previous version using the previous namespace?

Or, if not that, what does it stand for?

Note: if I use "Send to interactive" of a code snippet, this message does not appear.

Upvotes: 4

Views: 284

Answers (1)

scrwtp
scrwtp

Reputation: 13577

Someone with more detailed knowledge of FSI internals could no doubt give you a more complete answer, but for what it's worth:

  • FSI_XXXX is a dynamically created F# module that contains the "free" definitions you input into the REPL,
  • "Sending into interactive" does in fact put the definitions into such a module, despite that no explicit message is printed as in the "load" case,
  • I couldn't explicitly get hold of FSI_XXXX type, but it can be reached using reflection. FSI doesn't seem to allow something like "FSI_0001.Test" as a reference to the old version - can't tell if it's accidental or by-design.

Check the code below:

type Test = T of int

// this is the FSI_XXXX type, you can inspect it for more details.
let fsiType = typeof<Test>.DeclaringType 

Microsoft.FSharp.Reflection.FSharpType.IsModule fsiType // returns true

If you copy/paste and run this in the FSI window in Visual Studio, it will return something like the following:

type Test = | T of int
val fsiType : System.Type = FSI_0026
val it : bool = true

Upvotes: 3

Related Questions