简体   繁体   English

为什么F#Set不能实现ISet <T> ?

[英]Why doesn't the F# Set implement ISet<T>?

The .NET Framework is adding an ISet<T> interface with the 4.0 release. .NET Framework在4.0版本中添加了一个ISet<T>接口。 In the same release, F# is being added as a first-class language. 在同一版本中,F#被添加为一流语言。 F# provides an immutable Set<'T> class. F#提供了一个不可变的Set<'T>类。

It would seem logical to me that the immutable set provided would implement the ISet<T> interface, but it doesn't. 我认为提供的不可变集将实现ISet<T>接口,但事实并非如此。 Does anyone know why? 有谁知道为什么?

My guess is that they didn't want to implement an interface intended to be mutable, but I don't think this explanation holds up. 我的猜测是他们不想实现一个可变的接口,但我认为这种解释并不成立。 After all, their Map<'Key, 'Value> class implements IDictionary , which is mutable. 毕竟,他们的Map<'Key, 'Value>类实现了IDictionary ,它是可变的。 And there are examples elsewhere in the framework of classes implementing interfaces that are only partially appropriate. 并且在实现仅部分适当的接口的类的框架中的其他地方存在示例。

My other thought is that ISet<T> is new, so maybe they didn't get around to it. 我的另一个想法是ISet<T>是新的,所以也许他们没有解决它。 But that seems kind of thin. 但这似乎有点薄。

Does the fact that ISet<T> is generic (v. IDictionary , which is not) have anything to do with it? 是否事实ISet<T>是通用(诉IDictionary ,这是不)有什么关系呢?

Any thoughts on the matter would be appreciated. 对此事的任何想法将不胜感激。

Since no one else is jumping in, I'll add my speculation. 由于没有人跳进去,我会加上我的推测。 First of all, the majority of the IDictionary<'k,'v> interface still makes sense for an immutable dictionary; 首先,大多数IDictionary<'k,'v>接口对于不可变字典仍然有意义; it's really only adding or removing individual elements that won't work. 它实际上只是添加或删除不起作用的单个元素。 Secondly, there's a decent amount of code that has already been written which relies on IDictionary , so being able to use F# values with that code is a nice plus. 其次,已经编写了大量依赖于IDictionary的代码,因此能够将F#值与该代码一起使用是一个不错的选择。

On the other hand, several of ISet<'t> 's methods require mutation, including not just adding individual elements, but also several set mutating operators such as union and intersection. 另一方面, ISet<'t>的几个方法需要变异,不仅包括添加单个元素,还包括几个变异操作符,例如union和intersection。 Additionally, many set use cases are already subsumed by the IEnumerable<'t> interface - I think that it will be relatively rare for people to rely on ISet<'t> implementations for immutable set based code. 此外,许多设置用例已经被IEnumerable<'t>接口所包含 - 我认为人们依赖ISet<'t>实现来获取基于不可变集的代码是相对罕见的。

I don't think that genericity has anything to do with it - note that despite the MSDN documentation, F# maps implement the generic IDictionary interface, not the non-generic one. 我不认为泛型与它有任何关系 - 请注意,尽管有MSDN文档,但F#maps实现了通用IDictionary接口,而不是非泛型接口。

Offhand I don't think I was previously aware of ISet . 我不认为之前知道过ISet (Actually I looked back through old email, and found one mention of BCL plans for it--from 2008--but that was it. So I think it wasn't on our radar.) (实际上我回顾过旧的电子邮件,并从2008年发现了一个提到它的BCL计划 - 但就是这样。所以我认为它不在我们的雷达上。)

That said, F# strives to be source-compatible between its .NET 2.0 and .NET 4.0 bits, to the point of back-porting .NET 4.0 entities into FSharp.Core.dll version 2.0. 也就是说,F#努力在其.NET 2.0和.NET 4.0位之间进行源代码兼容,以便将.NET 4.0实体反向移植到FSharp.Core.dll版本2.0中。 For example, The 2.0 FSharp.Core contains System.Tuple , System.BigInteger , System.Threading.CancelationTokenSource (part of the async programming model), etc., and ISet would potentially be another bit of work to back-port (it's unclear to me if it would be 'necessary' to port it, though). 例如,2.0 FSharp.Core包含System.TupleSystem.BigIntegerSystem.Threading.CancelationTokenSource (异步编程模型的一部分)等,而ISet可能是后端口的另一项工作(目前还不清楚)对我来说,如果它是“必要的”移植它,但是)。

I'll file an issue to have a look, though it may be moot at this point in time. 我会提出一个问题来看看,虽然这个时间点可能没什么问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM