Write your first code in F#
Tags: tutorial, fsharp, functional
Published: 2021-07-21 10:45:51

---
title: Write your first code in F#
published: true
description: Learn F#, multiparadigm programming that's succinct, performant and robust
tags: tutorial, fsharp, functional
cover_image: https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gngjcgblgogxykob3cv0.png
---

F# is an open-source, cross-platform programming language that makes it easy to write succinct, performant, robust, and practical code.

## References

- **LEARN module** The first F# module of many was just published on LEARN, check it out [Take your first steps with F#](https://docs.microsoft.com/en-gb/learn/modules/fsharp-first-steps/)
- **LEARN module** The second module just published. [Write your first F# programs](https://docs.microsoft.com/en-gb/learn/modules/fsharp-first-program/)
- [F# docs](https://docs.microsoft.com/en-us/dotnet/fsharp/)

## Why F#?
There are many language features and aspects of the F# language that make it easy to be productive when writing code:

- **Succinct**: You write less code with F# that's also expressed in a clear manner.
- **Performant**: F# comes with built-in parallelism and concurrency. It also uses the fact that it's part of the .NET runtime to speed things up.
- **Robust**: There are language constructs that makes the code fault tolerant and robust like immutable by default, null value management and more.
- **Supports multiple programming paradigms**: F# lets you choose the patterns and practices most effective for solving problems by providing strong support for functional and object programming paradigms.

## How do I get started?

There are a few things you need to get started.

- **.NET SDK**. You need to install the .NET SDK to be able to buiild, run, test and also create F# projects. You can find the [F# SDK install](https://dotnet.microsoft.com/download) here
- **Ionide**. It's a VS Code plugin. It's not necessary to install, but it will give you things like Intellisense, tooltips, codelens, error highlight and more.

## Your first code

You can start writing F# by using the REPL called FSI, you can also scaffold an F# project using the `dotnet` executable.

### Create a project

You create a project using `dotnet` like so:

```bash
dotnet new console --language F# -o MyFSharpApp
```

Then you get a project with files:

- **Program.fs**, your entrypoint file
- **MyFSharpApp.csproj**, your project file that contains everything it needs to know to build the project like dependencies for example.

### What does the code look like?

Here you have the code of _Program.fs_. Itt contains the functions `from()` and `main()`. `main()` is the entry point of the app, as seen by `[<EntryPoint>]`. 

```fsharp
open System

// Define a function to construct a message to print
let from whom =
    sprintf "from %s" whom

[<EntryPoint>]
let main argv =
    let message = from "F#" // Call the function
    printfn "Hello world %s" message
    0 // return an integer exit code
```

The `from()` function takes the arg `whom` and the function body prints a string using the function `sprintf`.

## How do I learn more?

- **LEARN module** The first F# module of many was just published on LEARN, check it out [Take your first steps with F#](https://docs.microsoft.com/en-gb/learn/modules/fsharp-first-steps/)
- **LEARN module** The second module just published. [Write your first F# programs](https://docs.microsoft.com/en-gb/learn/modules/fsharp-first-program/)
- [F# docs](https://docs.microsoft.com/en-us/dotnet/fsharp/)