Skip to content
Learni
View all tutorials
Développement

How to Develop a Simple F# Application in 2026

Lire en français

Introduction

F# is a modern functional programming language developed by Microsoft on the .NET platform. It combines the power of functional programming with the .NET ecosystem, making it ideal for data processing, scientific applications, and backend systems. In 2026, F# continues to evolve with excellent integration in Visual Studio and VS Code. This tutorial helps you create a complete console application that calculates statistics on a list of numbers. You will learn core concepts such as functions, immutable lists, and pattern matching while working with real, executable code.

Prerequisites

  • .NET SDK 8.0 or higher installed
  • A code editor (Visual Studio Code with the Ionide extension recommended)
  • Basic programming knowledge (variables, functions)

Initialize the F# Project

terminal
dotnet new console -lang F# -o MonPremierProjetFsharp
cd MonPremierProjetFsharp

This command creates a complete F# console project with the standard folder structure and a Program.fs file ready to edit.

Display Hello World in F#

Program.fs
printfn "Bonjour depuis F# en 2026 !"

[<EntryPoint>]
let main argv =
    printfn "Hello, World !"
    0

The code prints a simple message. The main function marked with the EntryPoint attribute serves as the standard entry point for an F# console application.

Create a Calculation Function

We will now add a function that calculates the average of a list of numbers. F# encourages immutability and pure functions.

Add the Average Function

Program.fs
let calculerMoyenne (nombres: float list) =
    if List.isEmpty nombres then 0.0
    else List.sum nombres / float (List.length nombres)

[<EntryPoint>]
let main argv =
    let donnees = [12.5; 18.0; 9.75; 15.25]
    let moyenne = calculerMoyenne donnees
    printfn "La moyenne est : %.2f" moyenne
    0

This pure function accepts an immutable list and returns the average. It handles the empty list case to avoid division errors.

Use Pattern Matching

Program.fs
let analyserResultat moyenne =
    match moyenne with
    | m when m >= 15.0 -> "Excellent"
    | m when m >= 10.0 -> "Correct"
    | _ -> "Insuffisant"

[<EntryPoint>]
let main argv =
    let donnees = [12.5; 18.0; 9.75; 15.25]
    let moyenne = calculerMoyenne donnees
    let resultat = analyserResultat moyenne
    printfn "Résultat : %s" resultat
    0

Pattern matching with guards produces highly readable and exhaustive code for different value ranges.

Run the Program

terminal
dotnet run

The command compiles and executes the program. The output displays the average and corresponding analysis.

Best Practices

  • Always prefer pure functions and immutable data
  • Use pattern matching instead of complex if/else statements
  • Give your functions descriptive names in English or French
  • Test your functions with lists of different sizes
  • Keep your main function as simple as possible

Common Mistakes to Avoid

  • Forgetting to handle the empty list case in statistical calculations
  • Using mutable variables out of habit instead of let bindings
  • Ignoring F# compiler warnings that often indicate potential bugs
  • Not adding explicit types when type inference becomes ambiguous

Going Further

Deepen your F# knowledge with our dedicated training on functional programming and .NET development. Discover our Learni courses.