简体   繁体   English

System.Version没有在F#中实现System.IComparable

[英]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.

相关问题 System.Version未序列化 - System.Version not serialized C# - 没有从&#39;T&#39;到&#39;System.IComparable的隐式引用转换 <T> “ - C# - No implicit reference conversion from 'T' to 'System.IComparable<T>' Blazor:没有从“T”到“System.IComparable”的装箱转换或类型参数转换<t></t> - Blazor: There is no boxing conversion or type parameter conversion from 'T' to 'System.IComparable<T> LINQ排序:无法按“ System.IComparable”类型进行排序 - LINQ sorting: Cannot order by type 'System.IComparable' 没有从&#39;dungGenerator.Room&#39;到&#39;System.IComparable的隐式引用转换。 - There is no implicit reference conversion from 'dungGenerator.Room' to 'System.IComparable “UnityEngine.Vector2”类型必须可转换为“System.IComparable”<UnityEngine.Vector2> &#39; 将其用作泛型类 Graph 中的参数 &#39;T&#39;<T> - The type 'UnityEngine.Vector2' must be convertible to 'System.IComparable<UnityEngine.Vector2>' to use it as parameter 'T' in generic class Graph<T> 使用System.Version进行通用版本控制 - Using System.Version for general purpose versioning sql server中System.Version的数据类型 - Datatype for System.Version in sql server 如何在实体框架6中将System.Version映射为复杂类型 - How to map System.Version as Complex Type in Entity Framework 6 不实现System.IComparable.CompareTo(object) - Does not implement System.IComparable.CompareTo(object)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM