F# | Sheetly Cheat Sheet

Last Updated: November 21, 2025

F#

Functional-first .NET language

Basic Syntax

// Variables
let name = "John"
let age = 30
let mutable count = 0

// Functions
let add x y = x + y
let greet name = sprintf "Hello, %s" name

// Pattern matching
let describe x =
    match x with
    | 0 -> "zero"
    | 1 -> "one"
    | _ -> "many"

// Lists
let numbers = [1; 2; 3; 4; 5]
let doubled = List.map (fun x -> x * 2) numbers
let evens = List.filter (fun x -> x % 2 = 0) numbers

// Pipe operator
[1..10]
|> List.map (fun x -> x * 2)
|> List.filter (fun x -> x > 5)
|> List.sum

Type System

Item Description
int, float Numeric types
string Text
bool True/false
list Immutable list
option Some value or None
Result Ok value or Error
tuple (1, 'a')

Records and DUs

// Record type
type Person = {
    Name: string
    Age: int
}

let john = { Name = "John"; Age = 30 }

// Discriminated Union
type Shape =
    | Circle of radius: float
    | Rectangle of width: float * height: float

let area shape =
    match shape with
    | Circle r -> System.Math.PI * r * r
    | Rectangle (w, h) -> w * h

Best Practices

  • Use immutable data by default
  • Leverage pattern matching
  • Use pipe operator for composition
  • Interop seamlessly with C# and .NET

💡 Pro Tips

Quick Reference

F# combines functional and OOP paradigms

← Back to Data Science & ML | Browse all categories | View all cheat sheets