F# Cheat Sheet
Core syntax for F#, covering bindings, functions, pipelines, discriminated unions, and pattern matching on .NET.
2 PagesIntermediateMar 25, 2026
Values & Functions
Immutable bindings and function definitions.
fsharp
// Values and functionslet x = 42 // immutable bindinglet name = "SkillVeris"let add a b = a + b // function definitionlet square x = x * xprintfn "Sum: %d" (add 2 3) // formatted printlet mutable counter = 0 // explicitly mutablecounter <- counter + 1
Pipelines & Composition
The pipe operator and function composition.
fsharp
let isEven n = n % 2 = 0[1..10]|> List.filter isEven|> List.map (fun n -> n * n)|> List.sum|> printfn "Result: %d"// Function composition with >>let addThenDouble = (+) 1 >> (*) 2
Core Types
F#'s main type-system building blocks.
- record- Immutable named-field type: type Point = { X: int; Y: int }
- discriminated union- Sum type: type Shape = Circle of float | Square of float
- option- Represents an optional value: Some 5 or None
- tuple- Fixed-size grouping: let pair = (1, "a")
- unit- Type with a single value (), analogous to void
- list vs array- list: T list (immutable, linked); array: T[] (mutable, fixed size)
Pattern Matching
Matching on unions and options.
fsharp
type Shape = | Circle of radius: float | Rectangle of width: float * height: floatlet area shape = match shape with | Circle r -> System.Math.PI * r * r | Rectangle (w, h) -> w * hmatch Some 5 with| Some x when x > 0 -> printfn "positive %d" x| Some _ -> printfn "non-positive"| None -> printfn "none"
Pro Tip
Use |> liberally to keep data-transformation pipelines readable left-to-right instead of nesting function calls inside-out.
Was this cheat sheet helpful?
Explore Topics
#FCheatSheet#Programming#Intermediate#ValuesFunctions#PipelinesComposition#CoreTypes#PatternMatching#Functions#DevOps#CheatSheet#SkillVeris
Advertisement
Sri Hayavadhana Info-Tech
Professional Web Designing Services
- Responsive Websites
- E-commerce Solutions
- SEO Friendly Design
- Fast & Secure
- Support & Maintenance