types - 为什么这个 Discriminate Union 不接受 Set 类型的情况?
问题描述
我正在尝试创建一种新Set
类型:
type MySet<'t> = | List of list<'t>
| Sequence of seq<'t>
| Array of 't []
这可行,但如果我尝试为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>
我的猜测是这应该很容易修复,但即使我尝试了几件事,我也无法做到。
解决方案
数据结构的实现Set<'t>
要求其值可以进行比较,因此如果您的类型包含可以放入集合中的值,则必须提供相同的类型约束:
type MySet<'t when 't : comparison> =
| List of list<'t>
| Sequence of seq<'t>
| Array of 't []
| Set of Set<'t>
推荐阅读
- angular - 当我指定 sm 模态时,我仍然可以在后台看到 lg
- python - 为什么没有通过 Google Calendar API 将与会者添加到活动中?
- react-native - Expo:弹出到裸项目仅适用于 SDK 34 及更高版本
- python-3.x - 如何在 python/selenium 中为动态元素编写 xpath
- javascript - 将字符串传递给方法发送电子邮件
- python - 'function' 对象在新端点上没有属性 'get_extra_actions'
- sql - 错误:ntext 数据类型无法选择为 DISTINCT,因为它不可比较
- linux - 带有 Apache httpd.conf 文件的 Docker 卷权限
- layout - 当 LayoutBuilder 中的 FutureBuilder 时颤动无限循环
- rabbitmq - RabbitMQ 集群中镜像上持久消息的行为