F# Type System

Strong, static typing with inference

Type Inference

let add x y = x + y
// Compiler infers: int -> int -> int

let concat a b = a + b
// Compiler infers: string -> string -> string

Discriminated Unions

Definition

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

Usage

let myCircle = Circle 5.0
let myRect = Rectangle (4.0, 6.0)

Records

type Person = {
    Name: string
    Age: int
    Email: string option
}

let john = {
    Name = "John Doe"
    Age = 30
    Email = Some "john@example.com"
}