📅  最后修改于: 2021-01-01 05:14:24             🧑  作者: Mango
F#允许您编写通用函数,方法,类型,变量等。它有助于避免每种类型的代码重复。通过编写通用代码,您可以将其应用于任何类型或值。
句法:
// Generic function.
let function-name parameter-list =
function-body
// Generic method.
[ static ] member object-identifer.method-name parameter-list [ return-type ] =
method-body
// Generic class, record, interface, structure,
// or discriminated union.
type type-name type-definition
let genericFunctionExample<'T> x y =
printfn "%A %A" x y
genericFunctionExample 1 2
输出:
1 2