jonnifyfsharp

Chapter C1

The language, in depth

F# taught on its own terms — not a curiosity beside C#, but a complete way to build software.

This is the spine of the course. Nine modules take F# from its smallest parts to its most expressive: values and types, let bindings, functions, the pipe and composition, pattern matching, discriminated unions and records, the collections, Option and Result, and finally computation expressions. Every snippet is valid, idiomatic F# you can paste into F# Interactive and run. Read them in order — each module leans on the one before it.

How to read this chapter

F# is functional-first: functions and immutable values are the default tools, and the type system works for you rather than against you. The chapter is built so each module leans on the one before it. Values and their types come first, because everything else is made from them. Bindings name those values. Functions transform them. The pipe and composition wire functions together. Pattern matching, unions, and records shape the data; Option and Result turn absence and failure into ordinary values; computation expressions tie the threads into a small language of your own.

One habit to start with: read the types. F# infers a type for every expression, and F# Interactive — the REPL, started with dotnet fsi — echoes it back. Select an expression below to see what FSI prints: the value, and the type it inferred.

F# Interactive · evaluate an expression

expression what you type F# Interactive infers & evaluates inferred type int
// you type
1 + 2 * 3;;
// FSI prints
val it : int = 7
Multiplication binds tighter than addition, as in arithmetic, so the result is 7 — an int, inferred without an annotation.

If you can read the type FSI prints, you can read most F#. The type is the contract; the value is one inhabitant of it.

The nine modules

The chapter in order, the final module a hands-on lab. Each module carries three dives, and each leans on the one before it — values, then names, then functions, then how they compose and combine.

built lesson ready

References

Sources

Related in this course