-
Notifications
You must be signed in to change notification settings - Fork 11
Generics
Andrei Kurosh edited this page Aug 16, 2026
·
1 revision
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"An algebraic type can have parameters specified at the base:
type Option<T>
None
Some of T
let n = None<int>
let s = Some 2A function can also specify generic arguments:
fun add<T> (item:T list:List<T>) ->
list.Add item
add 1 new [[ 0 ]]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