DEV Community

Cover image for F# For Dummys - Day 3 New Program
AllenZhu
AllenZhu

Posted on • Updated on

F# For Dummys - Day 3 New Program

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
Enter fullscreen mode Exit fullscreen mode

this command will create a program named MyFSharpApp in F#

Image description

open your file explorer, open the folder created in last step, let's check what it contains

Image description

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

Image description

3、go back to our command window, input

cd MyFSharpApp
Enter fullscreen mode Exit fullscreen mode

it will change directory (cd) to MyFSharpApp dir

image.png

4、run your code

dotnet run
Enter fullscreen mode Exit fullscreen mode

output

Image description

5、check our app dir again

Image description

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

Image description

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()
Enter fullscreen mode Exit fullscreen mode

and run it again

dotnet run
Enter fullscreen mode Exit fullscreen mode

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

Image description

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

Top comments (0)