Вопрос

I recentry found out that there's a bunch of immutable collections in .Net

F# is a language with focus on immutability and it has its own immutable data types. Interestingly, I saw no reference to abovementioned immutable collections in any reading on F#.

I am wondering is there any relationship between those immutable collections and F# collections? Is there any guideline what to use? What is better, F# Map<_,_> or ImmutableDictionary(TKey, TValue) and so on?

UPDATE Maybe I could ask it as follows: does anybody have any experience using both these libraries in same project or have compared their productivity? Or it's just like that - first are for C# and latter are for F# and that's it?

Это было полезно?

Решение

The reason for this duplication is simply that System.Collections.Immutable is a recent addition and is intended for use in C#, so its designers understandably didn't want people to have to reference FSharp.Core.dll.

As for choosing between the two, I would use System.Collections.Immutable in C# code and in F# code that is intended to be used from C#, and Microsoft.FSharp.Collections in all other F# code. AFAIK there is no significant difference in terms of performance. Typical code will look like chained method calls with S.C.I and series of |> calls with M.F.C but this is just a syntactic difference really -- conceptually it's the same thing.

Другие советы

Just to add my 2 cents: my current research gives an impression that System.Collections.Immutable is something that should help to program F# while you program C# ))

Here's MSDN blog post on them. It references another post (MSDN too). And in this article there's a broken reference to T4 template which can be used to create immutable objects easily in C#: here's a TT file and here's a scary result of transformation.

This is clearly a great work, but is seems to reproduce (by using System.Collections.Immutable) features that already and naturally exist in F#.

Hence the answer currently seems to be - System.Collections.Immutableare for C# and Microsoft.FSharp.Collections are for F# and that's it.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top