[英]System.Version doesn't implement System.IComparable in F#
I want to sort a sequence of Version
objects in F#: 我想在F#中对一系列Version
对象进行排序:
let maxVersion =
versions
|> Seq.max (fun version -> version)
The compiler produces the following error message: 编译器生成以下错误消息:
The type '(seq -> 'a)' does not support the 'comparison' constraint. 类型'(seq - >'a)'不支持'比较'约束。 For example, it does not support the 'System.IComparable' interface 例如,它不支持“System.IComparable”接口
When I hit F12 in Visual studio to take a look at the metadata of Version
it says that Version
only implements ICloneable
, but not IComparable
. 当我在Visual Studio中点击F12来查看Version
的元数据时,它说Version
只实现了ICloneable
,而不是IComparable
。 But when I go to sourceof.net it says it implements IComparable
as well as some other interfaces. 但是,当我访问sourceof.net时,它表示它实现了IComparable
以及其他一些接口。
Does F# use a different version of the .NET framework? F#是否使用不同版本的.NET框架?
The error message is telling you that (seq->'a)
does not implement IComparable
which is true since (seq->'a)
is a function, not a sequence. 错误消息告诉你(seq->'a)
没有实现IComparable
,这是真的,因为(seq->'a)
是一个函数,而不是一个序列。
If you look at the signature of Seq.max
it takes only the sequence as parameter. 如果你看一下Seq.max
的签名, Seq.max
需要序列作为参数。 Remove the lambda (fun version -> version)
and it should be alright. 删除lambda (fun version -> version)
,它应该没问题。
Otherwise, if you want to apply a key generator function for the sort, use instead Seq.maxBy
否则,如果要为排序应用密钥生成器函数,请使用Seq.maxBy
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.