Sol*_*lma 3 f# types set discriminated-union
我正在尝试创建一个新Set
类型:
type MySet<'t> = | List of list<'t>
| Sequence of seq<'t>
| Array of 't []
Run Code Online (Sandbox Code Playgroud)
这有效,但如果我尝试为Set
类型本身添加一个案例,我会收到一条消息:a type parameter is missing a constraint 'when t: comparison'
type MySet<'t> = | List of list<'t>
| Sequence of seq<'t>
| Array of 't []
| Set of Set<'T>
Run Code Online (Sandbox Code Playgroud)
我的猜测是应该很容易修复,但即使我尝试了几件事我也做不到.
Set<'t>
数据结构的实现要求可以比较其值,因此如果您的类型包含可以放入集合的值,则必须提供相同的类型约束:
type MySet<'t when 't : comparison> =
| List of list<'t>
| Sequence of seq<'t>
| Array of 't []
| Set of Set<'t>
Run Code Online (Sandbox Code Playgroud)