DEV Community

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

Posted on • Edited on

1

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

Speedy emails, satisfied customers

Postmark Image

Are delayed transactional emails costing you user satisfaction? Postmark delivers your emails almost instantly, keeping your customers happy and connected.

Sign up

Top comments (0)

Heroku

Simplify your DevOps and maximize your time.

Since 2007, Heroku has been the go-to platform for developers as it monitors uptime, performance, and infrastructure concerns, allowing you to focus on writing code.

Learn More

👋 Kindness is contagious

Immerse yourself in a wealth of knowledge with this piece, supported by the inclusive DEV Community—every developer, no matter where they are in their journey, is invited to contribute to our collective wisdom.

A simple “thank you” goes a long way—express your gratitude below in the comments!

Gathering insights enriches our journey on DEV and fortifies our community ties. Did you find this article valuable? Taking a moment to thank the author can have a significant impact.

Okay