Skip to content
Tutorials Center
My learning

Topics

Lesson 1 of 37 ยท Getting Started

What Is F#? A Functional-First Language for .NET

Meet F#, the functional-first language on .NET. Learn what makes it different, where it is used, how it compares with C#, and what you will build in this course.

F# (pronounced "F sharp") is a functional-first programming language that runs on .NET. You write short, precise code, the compiler infers most types for you, and a large class of bugs (null references, forgotten cases, mixed-up units) is caught before the program ever runs. It is open source, free, and developed by Microsoft together with a community of contributors.

"Functional-first" does not mean "functional only". F# is a multi-paradigm language: you can write functions and immutable data, but also classes, interfaces, mutable variables and loops when they are the right tool. The language simply nudges you toward the style that tends to produce the most reliable programs. This lesson explains the big ideas, so the syntax in the next lessons has a reason behind it.

Honest note about this course: the site can run C# but not F#. F# examples are shown as read-only code, and where it helps, a small runnable C# stand-in shows the same idea in a language the runner supports. Each stand-in is labelled. To run the F# code yourself, follow Installing .NET and using F# Interactive.

The big ideas

Why people choose F#

Concise Less ceremony, more logic
Safe Types catch mistakes early
Immutable Values do not change by surprise
Composable Small functions snap together

Four ideas that shape every F# program.

1 / 3

Concise and type-inferred

F# is statically typed, so every value has a type known at compile time. Unlike older statically typed languages, you rarely write the types down. The compiler works them out:

FSHARP
let price = 19.99          // float
let name = "Ada"           // string
let double x = x * 2       // int -> int

You get the safety of types with the lightness of a scripting language.

Immutable by default

In F#, let x = 5 binds the name x to the value 5 forever. You cannot reassign it. To get a different value you create a new one. Immutability makes programs easier to reason about: when you read a function you know nobody can change its inputs behind its back, which also makes concurrent code far safer.

When you really need a changeable variable, you opt in with the keyword mutable. That explicit opt-in is the point: mutation is visible and deliberate.

Expressions, not statements

Almost everything in F# produces a value. An if returns a value, a match returns a value, even a block of code returns the value of its last line. There is no separate "statement" world and "expression" world, so pieces fit together without temporary variables.

FSHARP
let describe n =
    if n < 0 then "negative"
    elif n = 0 then "zero"
    else "positive"

Functions are values

You can store a function in a variable, pass it to another function and return it from one. Most F# programs are built by writing many small functions and combining them with the pipeline operator |>:

FSHARP
[ 1 .. 10 ]
|> List.filter (fun n -> n % 2 = 0)
|> List.map (fun n -> n * n)
|> List.sum

Read it top to bottom: take the numbers 1 to 10, keep the even ones, square them, add them up. The result is 220. You will meet pipelines properly in Pipelines and composition.

Types that model the real world

F# has records (named fields), discriminated unions (a value that is exactly one of several cases) and pattern matching to take them apart. Together they let you describe a business domain so precisely that illegal states cannot even be written down. The compiler also warns when you forget to handle a case. Chapters 5 and 6 are devoted to this.

No null by accident

Ordinary F# types do not accept null. When a value may be missing you say so with the option type (Some 3 or None), and the compiler forces you to deal with both possibilities. That removes the famous "billion-dollar mistake" from day-to-day code.

F# and C# side by side

Both languages compile to the same intermediate language and use the same libraries, so you can mix them in one solution. They differ in defaults:

Topic F# C#
Main style Functional-first Object-oriented first
Variables Immutable by default Mutable by default
Types Inferred almost everywhere Declared (with var)
Null Not allowed in F# types Allowed (nullable analysis helps)
Blocks Indentation Curly braces
Missing a case Compiler warning for incomplete match Warning for switch expressions

The next example is a C# stand-in for the F# pipeline above. LINQ is C#'s closest relative to F# pipelines; it computes the same number.

C# C# stand-in: the same pipeline in LINQ

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with Console.ReadLine()), it gets the next line from this box.

Where F# is used

  • Finance and insurance: pricing, risk, and trading systems, where correctness is worth money.
  • Data and machine learning: scripting analysis, with libraries for data frames, plotting and ML.
  • Web and cloud: APIs and background services on ASP.NET Core and Azure.
  • Compilers and tools: the language is a favorite for parsers and interpreters thanks to unions and pattern matching.
  • Front end: tools such as Fable compile F# to JavaScript.

What you will learn

Chapters 1 to 4 give you the core: tooling, values, functions and collections. Then you will model data with records and unions, handle absence and errors with pattern matching and options, write asynchronous and parallel code, talk to C# libraries, and finish with projects.

flowchart LR
    A["Getting started"] --> B["Basics"]
    B --> C["Functions"]
    C --> D["Collections"]
    D --> E["Types and matching"]
    E --> F["Async and interop"]
    F --> G["Projects"]

The path through the course: each chapter builds on the previous one.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. What does "functional-first" mean for F#?

    F# is multi-paradigm. Functional style is the default, and other styles are available when you need them.
  2. 2. What happens when you write let x = 5 in F#?

    Let bindings are immutable by default. You opt into change with the mutable keyword.
  3. 3. How does F# represent a value that may be missing?

    Option makes absence explicit, and the compiler makes you handle both cases.
  4. 4. Which runtime does F# use?

    F# compiles to .NET and can use any .NET library, including those written in C#.

Summary

  • F# is a functional-first, statically typed language on .NET with strong type inference.
  • Values are immutable by default; almost everything is an expression.
  • Functions are values, and pipelines combine them.
  • Records, unions and pattern matching model data; option replaces null.
  • F# and C# interoperate freely, and they run on the same platform.

Next: Installing .NET and using F# Interactive