F# For Dummys - Day 3

90 阅读1分钟

Today we compile a F# file and run it on local environment
for a web editor user, your online environment will process the same procedure to run your f# file

  1. open a command window (input 'cmd' in search text input, or press Win button then input 'cmd')
  2. input command below
dotnet new console -lang F# -o MyFSharpApp

this command will create a program named MyFSharpApp in F#

image.png

let's check what it create for us

image.png
the only file you need to care about now is the f# source code file which end with .fs
let open our source code in nodepad

image.png 3. go back to our command window, input

cd MyFSharpApp

it will change directory (cd) to MyFSharpApp dir

image.png
4. run your code

dotnet run

output

image.png
5. check our app dir again

image.png
we got a new dir named 'bin', let's see what's inside

image.png it contains the comile output, MyFSharpApp.exe is our application file, you can ignore other output files for right now 6. let's change our source code a little bit like below

open System
printfn "Hello from F#"
Console.ReadLine()

and run it again

dotnet run

go to the comile output dir: bin/Debug/net8.0
double click our new application file: MyFSharpApp.exe

image.png you will see the same result like in the command window, right
actually in the command window, it also call MyFSharpApp.exe at backend, so it's the same result when you execute the exe file by double click it