F# interop - Passing Immutable Collections & F# Collections into F# Functions from C# #7833
-
I have noticed that when I run F# functions in C# that return collections (like a List), they are returned as an FSharp variation (which is not a problem), however when I pass a collection into an F# function as a parameter, I can only pass in a mutable version. Is there a way to pass in either the FSharp or Immutable variant? I know that I can just run ToList() on pass in, however I don't want to open the list up to possibly being mutated if it is already in an immutable format. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
This is not precise. The F# collection syntax provides F# collections. There are no limitations to use standard collections in F#.
You can just declare the return type as F# collection. It will be seen as |
Beta Was this translation helpful? Give feedback.
This is not precise. The F# collection syntax provides F# collections. There are no limitations to use standard collections in F#.
You can just declare the return type as F# collection. It will be seen as
FSharp.Collections.List<T>
. For immutability, you can useSystem.Collections.Immutable.ImmutableArray<T>
and others.