F# For Dummys - Day 3 New Program
AllenZhu
Posted on May 16, 2024
Today we create a F# program and run it on local environment
for a web editor user, your online environment will process the same procedure to run your f# code
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#
open your file explorer, open the folder created in last step, let's check what it contains
the only file you need to care about now is the f# source code file which end with .fs
open our source code file(Program.fs) in notepad
3、go back to our command window, input
cd MyFSharpApp
it will change directory (cd) to MyFSharpApp dir
4、run your code
dotnet run
output
5、check our app dir again
we got a new dir named 'bin', let's see what's inside
it contains the compile output, MyFSharpApp.exe is our application file, you can ignore other output files for right now
6、make the output window wait, notice the web browser environment don't support this step
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
you will see the same result like in the command window, right
actually in the command window, it also calls MyFSharpApp.exe at backend, so it's the same result as you execute the exe file by double click it
if you wonder what is compile?
a simple way to explain:
it's a translator who translate your source code to Intermediate Language (IL) code, the .NET runtime understand IL, the JIT compiler will translate IL into machine code that CPU only understand
well, it seems not that simple, we don't dive deep here
Posted on May 16, 2024
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.