More particularly, I really want an immutable/shared linked list, and I think having immutable maps and sets would be nice too. As long as I don’t have to worry about the core implementation, I can easily add extension methods/subclass/wrap it to provide a reasonably slick external interface for myself to use.
Is there any reason I shouldn’t do this? Performance, incompatibility, etc.?
The types in the F# library (such as
Set,Mapandlist) were not designed to be used from C#, so I wouldn’t generally recommend using them directly. It can be done and some basic operations will work well (e.g. adding elements to an immutable map and checking if an element exists). However, there are some issues:F# also has functionality in modules (
MapModulefor an immutable map) and as a C# user, you would expect to see these as members.F# functions are not represented as
Func<_, _>delegates, but using some special F#-specific way. This means that using higher-order functions will be difficult.So, in summary, I think that a better approach is to wrap the F# data type into a class (implemented in F#) that exposes the methods you need to a C# developer in a friendly way. You can e.g. easily declare an F# method that takes
Func<_, _>delegate and calls F# higher-order function in a module.