在F#中,某些类型具有特殊的通用语法(我不确定它的名称),因此您可以执行以下操作:
int list // instead of List<int>
int option // instead of Option<int>
Run Code Online (Sandbox Code Playgroud)
在"通用类型"下:
通用类型
type-parameter generic-type-name |
'a list要么
generic-type-name <type-parameter-list> |
list<'a>
和"构造类型":
构造类型(提供特定类型参数的泛型类型)
type-argument generic-type-name
要么
通用类型名称<类型参数列表>
type dave<'a> = {
V : 'a
};;
let stringDave: dave<string> = { V = "string" };;
//val stringDave : dave<string> = {V = "string";}
let intDave : int dave = { V = 123 };;
//val intDave : dave<int> = {V = 123;}
Run Code Online (Sandbox Code Playgroud)