Can't run a .fsx file in interactive mode once a module is defined · Issue #1169...
source link: https://github.com/dotnet/fsharp/issues/11699
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Is your feature request related to a problem? Please describe.
Coming from Python world, I create a simple file sum.fsx
with a function:
let add x y = x + y
Next I add a validation test that gets executed when I run dotnet fsi sum.fsx
:
let add x y = x + y if fsi.CommandLineArgs = [| __SOURCE_FILE__ |] then assert(add 1 2 = 3) printfn "my code tested fine"
Next I create another file program.fsx
, where sum.fsx
gets used:
#load "sum.fsx" open Sum printfn $"sum of 10 and 15 is {add 10 15}"
In order to keep things tidy (and compatible with .fsproj type programs), I prepend an explicit module Sum
to sum.fsx
module Sum let add x y = x + y if fsi.CommandLineArgs = [| __SOURCE_FILE__ |] then assert(add 1 2 = 3) printfn "my code tested fine"
And my program.fsx
runs as expected.
But now testing sum.fsx
fails with:
dotnet fsi sum.fsx
/home/peter/test/sum.fsx(4,1): error FS0010: Unexpected start of structured construct in definition. Expected '=' or other token.
I.e. it refuses to run files starting with module
.
Describe the solution you'd like
I'd like fsharp not to complain and run the file as expected.
Describe alternatives you've considered
The alternative is to split the sum.fsx
into two files where the other file contains just the test part and doesn't start with module
.
But it's really annoying.
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK