Fsharp: Loading .fs files from .fsx files in Interactive mode gives wrong error messages.

Created on 28 Mar 2016  路  3Comments  路  Source: dotnet/fsharp

b.fsx:

#if INTERACTIVE
#load "a.fs"
#endif

printfn "Hello"

a.fs:

module a

#if INTERACTIVE
#r "mscorlib.dll"
#endif

Running b.fsx in Interactive causes:
a.fs(4,1): error FS0076: #r directives may only occur in F# script files (extensions .fsx or .fsscript). Either move this code to a script file, add a '-r' compiler option for this reference or delimit the directive with '#if INTERACTIVE'/'#endif'.

In here the directive is clearly delimited by #if INTERACTIVE/#endif. It would be great if .fs files like the above could be loaded from script files.

Area-Compiler Severity-Low bug

Most helpful comment

@dsyme not sure you understood @mrakgr claim here. The compiler is giving an error that is not useful at all because even if guarding the#r line with #if INTERACTIVE, it keeps complaining.

All 3 comments

The message clearly says that #r directives may only occur in F# script files, so this is by design

@dsyme not sure you understood @mrakgr claim here. The compiler is giving an error that is not useful at all because even if guarding the#r line with #if INTERACTIVE, it keeps complaining.

We use F# for fast ptototyping, firstly we write the code in Interactive mode (short REPL). Some time it is useful to compile the code of the prototype without porting it in to C#. (Compiled code is more handy from the point of deploying and solution management).
So, we write the script during the problem investigation, and when investigation is compete, we want to compile the code.
So the solution look like:

a.fs:

#if INTERACTIVE
#r "SomeUsefullAssemblyReferencedInProject.dll"
// Load additional
#load "FsLab.fsx" ....
open Plotly
#endif
open SomeUsefullAssemblyNamespace
module AModule =
  let doTheJob() = "Hello"
#if INTERACTIVE
  let problemInvestigationPlayground() =
    let jobResult = doTheJob()
    Plot.Show(jobResult)
#endif

when draft of AModule is ready, I want to write code for BModule that use AModule
b.fs

#if INTERACTIVE
#load "a.fs"
#endif
module BModule =
    let doTheJob() = AModule.doTheJob().....
#if INTERACTIVE
    let bModulePlayground() = ......
#endif

But error FS0076 occure, why do not allow #I and #r directives in fs files under the INTERACTIVE condition?

Was this page helpful?
0 / 5 - 0 ratings