Learn FSHARP with Real Code Examples

Updated Nov 18, 2025

Explain

F# is functional-first but supports OOP and imperative features.

Runs on .NET, giving access to the entire .NET ecosystem.

Popular in finance, data engineering, scientific computing, and reliable backend services.

Core Features

Expressions over statements

Powerful type inference

Discriminated unions

Pattern matching everywhere

Pipelining with |> operator

Async workflows

Basic Concepts Overview

Immutability

Discriminated unions

Record types

Sequences, lists, arrays

Pattern matching

Pipelines & higher-order functions

Project Structure

Program.fs (entry point)

Library modules in separate .fs files

.fsproj config

paket.dependencies / nuget

tests/ folder

Building Workflow

Create project via dotnet new console -lang F#

Define modules & functions

Add dependencies

Use fsi for exploration

Build & run

Deploy via .NET runtime

Difficulty Use Cases

Beginner: basic functions & lists

Intermediate: DU’s, records, modules

Advanced: async workflows, computation expressions

Expert: DDD modeling, compilers, financial engines

Comparisons

More concise than C#

More enterprise-ready than Python

More type-safe than JavaScript

Less concurrency-focused than Elixir

More accessible tooling than Haskell

Versioning Timeline

2005 – Initial Microsoft Research release

2010 – F# 2.0 (async workflows)

2014 – F# 3.0 (type providers)

2015–2025 – Continuous .NET Core improvements

Glossary

Computation Expression: workflows like async

DU: discriminated union

Record: immutable structured type

Pipeline operator: forward value passing

Sequence: lazy collection