f# - 警告 FS1178“不支持结构平等”
问题描述
我尝试在大型代码库上启用 5 级警告,它主要触发了数百个:
警告 FS1178 结构、记录或联合类型“Foo”不支持结构相等,因为类型“(单元 -> IBar 选项)”不满足“平等”约束。考虑将 'NoEquality' 属性添加到类型 'Foo' 以阐明该类型不支持结构相等
我们的许多类型引用 C# 类型,或包含函数类型(如上)。NoComparison
根据需要遍历所有这些和/NoEquality
属性会给我们带来什么好处?
解决方案
如果您尝试比较Foo
代码中其他地方的实例,[<NoComparison>]
或[<NoEquality>]
on的存在Foo
将使后续代码生成的编译器错误更容易理解。
没有属性的例子:
type Foo =
{
Func : int -> int
}
let problem = Set<Foo>
(*
Compiler error:
The type 'Foo' does not support the 'comparison' constraint
because it is a record, union or struct with one or more
structural element types which do not support the
'comparison' constraint. Either avoid the use of comparison
with this type, or add the 'StructuralComparison' attribute
to the type to determine which field type does not support
comparison
*)
带有属性的示例:
[<NoComparison>]
type Foo =
{
Func : int -> int
}
let problem = Set<Foo>
(*
Simpler compiler error:
The type 'Foo' does not support the 'comparison' constraint
because it has the 'NoComparison' attribute
*)
推荐阅读
- android - Android CameraX - 当相机检测到屏幕上的形状时自动捕获图像
- c++ - 如何在 C/C++ 中通过 void 指针传递数组
- docker - 使用卷挂载将文件从 docker 容器复制到主机,同时启动容器
- c# - 握手服务器 websocketsharp 库出错
- python - Python 嵌套导入
- docker - 带有 docker 和 yarn 的 SSH 私有仓库
- java - 安卓手机无法连接电脑
- pdf - 如何在乳胶中每页只有一个长表(从页面顶部开始)?
- node.js - 诊所火焰图:尝试阅读图表以确定修复
- c# - 如何操作将路由与多个文件夹链接,而不仅仅是控制器和操作?