Core Syntax at a Glance
F# uses let for immutable bindings, let mutable for mutable ones, -> in lambda and match expressions, and significant indentation, the offside rule, instead of braces. Functions are curried by default, so let add x y = x + y can be partially applied as add 5, producing a new function awaiting the second argument, a building block for point-free, pipeline-friendly code.
Cricket analogy: Like a quick-reference card showing standard field placements for a fast bowler, the compressed cheat sheet a captain like Pat Cummins glances at: F#'s let, ->, and indentation rules are the compressed cheat sheet for reading any F# function at a glance.
Collections and Common Functions
The core F# collection modules, List, Array, and Seq, each expose consistent operations such as map, filter, fold, sortBy, and iter, with Seq being lazily evaluated for large or infinite sequences, List being an immutable singly-linked list ideal for recursive processing, and Array being mutable, fixed-size, and fastest for random access and interop with .NET APIs expecting arrays.
Cricket analogy: Like choosing between a Test match squad, List, a methodical, immutable roster for the series, a T20 franchise squad, Array, fixed-size with fast rotation for quick matches, and an ongoing domestic season, Seq, players evaluated lazily match by match: each format suits a different situation.
Modules, Types, and F# Interactive
Group related functions and types with module, define records with { Field: Type } syntax and discriminated unions with type X = CaseA | CaseB of int, and use F# Interactive, dotnet fsi, to load and evaluate script files (.fsx) or paste expressions directly for quick experimentation without a full project build.
Cricket analogy: Like organizing a cricket board's structure into departments, a men's team module, a women's team module, a domestic module: F#'s module keyword groups related functions and types the same organized way.
// Bindings
let x = 42 // immutable
let mutable y = 0 // mutable
y <- y + 1 // mutation uses <-
// Functions (curried, partial application)
let add x y = x + y
let addFive = add 5 // partial application
// Records and discriminated unions
type Point = { X: float; Y: float }
type Shape =
| Circle of radius: float
| Square of side: float
// Pattern matching
let area shape =
match shape with
| Circle r -> System.Math.PI * r * r
| Square s -> s * s
// Pipelines and collections
[1..10]
|> List.filter (fun n -> n % 2 = 0)
|> List.map (fun n -> n * n)
|> List.sumRun dotnet fsi from a terminal to launch F# Interactive, then paste expressions and end each with ;; to evaluate immediately, ideal for testing a function or exploring a library API without creating a full project.
Remember that F# curried functions mean add 5 is valid on its own, returning a new function, not a partial-application error; forgetting this can lead to confusing type errors when a function is accidentally under-applied and passed where a fully-applied value was expected.
- let binds immutable values by default; use let mutable plus <- for mutation.
- Functions are curried by default, enabling partial application like add 5.
- List is immutable/linked, Array is mutable/fixed-size and fast for random access, Seq is lazily evaluated.
- Records use { Field: Type } syntax; discriminated unions use type X = CaseA | CaseB of ....
- The pipeline operator |> and functions like map/filter/fold/sortBy are core to idiomatic collection processing.
- F# Interactive (dotnet fsi) lets you evaluate expressions and .fsx scripts without a full build.
Practice what you learned
1. What syntax mutates a let mutable binding in F#?
2. What does it mean that F# functions are curried by default?
3. Which collection type is lazily evaluated in F#?
4. How do you define a discriminated union in F#?
5. What command launches F# Interactive from a terminal?
Was this page helpful?
You May Also Like
F# vs C#
A practical comparison of F# and C# across paradigm, type safety, syntax, and when to choose each on the .NET platform.
F# Best Practices
Guidelines for writing idiomatic, maintainable F# code covering function composition, project organization, and error handling.
Building a Console App in F#
A hands-on walkthrough of scaffolding, structuring, and handling input/output and exit codes in an F# console application.
Related Reading
Related Study Notes in Programming
Browse all study notesApache Spark Study Notes
Programming · 30 topics
ProgrammingApache Flink Study Notes
Programming · 30 topics
ProgrammingHadoop Study Notes
Programming · 30 topics
ProgrammingSnowflake Study Notes
Programming · 30 topics
ProgrammingApache Airflow Study Notes
Programming · 30 topics
Programmingdbt (Data Build Tool) Study Notes
Programming · 30 topics