Skip to content
Andrei Kurosh edited this page Aug 16, 2026 · 1 revision

Generic records

A record can be defined to contain generic type arguments:

record Pair<T1, T2>
    Left: T1
    Right: T2

let p = new Record<int, string> 1 "2"

Generic algebraic types

An algebraic type can have parameters specified at the base:

type Option<T>
    None
    Some of T
let n = None<int>
let s = Some 2

Generic functions

A function can also specify generic arguments:

fun add<T> (item:T list:List<T>) ->
    list.Add item

add 1 new [[ 0 ]]

Generic constraints

A generic argument can be constrained when needed:

fun foo<T = new & class & IFoo> () -> ...

The possible constraints (in any order, joined by &) are:

  • new: requires a parameterless constructor on the type
  • class: requires the type to be a reference
  • struct: requires the type to be a struct
  • identifier: an interface that the type must implement

Clone this wiki locally