I have the following code in a Test.fs
file:
namespace Testing
module test1 =
let Run =
printfn "Test1"
module test2 =
let Run =
printfn "Test2"
In my Program.fs
I am calling:
[<EntryPoint>]
let main argv =
let sw = Stopwatch.StartNew()
printfn "%A" Testing.test1.Run
sw.Stop()
printfn "Problem took %d minutes, %d seconds, and %d milliseconds" sw.Elapsed.Minutes sw.Elapsed.Seconds sw.Elapsed.Milliseconds
let s = Console.ReadLine()
0 // return an integer exit code
This outputs
Test1
Test2
Why is Test2
being outputting even though I am only calling Test1.Run
?
test1.Run
is not a function, it is a value. When you open a module you execute all top-level code in that module. In this case you are defining test1.Run
and test2.Run
which are both bindings rather than functions.
I can't tell from what you posted exactly what is happening, but it's clear that your main function is not getting called, otherwise printfn "%A" Testing.test1.Run
would print <null>
and printfn "Problem took %d minutes, %d seconds, and %d milliseconds" sw.Elapsed.Minutes sw.Elapsed.Seconds sw.Elapsed.Milliseconds
would print something as well.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With