System.Version不会F#中实现System.IComparable [英] System.Version doesn't implement System.IComparable in F#
问题描述
我要排序版本序列
F#中的对象:
I want to sort a sequence of Version
objects in F#:
let maxVersion =
versions
|> Seq.max (fun version -> version)
编译器生成以下错误消息:
The compiler produces the following error message:
类型'(SEQ - >'一)不支持比较的约束。例如,它不支持'System.IComparable'接口
The type '(seq -> 'a)' does not support the 'comparison' constraint. For example, it does not support the 'System.IComparable' interface
当我在Visual Studio中打F12来看看版本的元数据
它说,版本
只工具 ICloneable
,而不是 IComparable的
。但是,当我去 sourceof.net 它说,它实现 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
. But when I go to sourceof.net it says it implements IComparable
as well as some other interfaces.
难道F#使用不同版本的.NET框架?
Does F# use a different version of the .NET framework?
推荐答案
该错误信息是告诉你,(SEQ - >'一)
不执行 IComparable的
,因为(SEQ - >'一)。
是一个函数,而不是一个序列
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.max的签名
只需要在序列参数。
删除的λ(FUN版 - >版本)。
,它应该是正常的。
If you look at the signature of Seq.max
it takes only the sequence as parameter.
Remove the lambda (fun version -> version)
and it should be alright.
另外,如果你想申请一个密钥生成器功能的排序,而不是使用 Seq.maxBy
Otherwise, if you want to apply a key generator function for the sort, use instead Seq.maxBy
这篇关于System.Version不会F#中实现System.IComparable的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!