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.Immutable
are for C# and Microsoft.FSharp.Collections
are for F# and that's it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With