F# RFC FS-1094 - immarray as FSharp.Core collection, an abbreviation for System.Collections.Immutable.ImmutableArray
The design suggestion A normative immutable array type has been marked "approved in principle".
This RFC covers the detailed proposal for this suggestion.
- Implementation TBD
- Design Review Meeting(s) with @dsyme and others invitees
- Discussion
A new collection type 'T immarray will be added to FSharp.Core, and FSharp.Core will now depend on System.Collections.Immutable
Prior to this RFC F# programming has no strong opinion on an immutable array data structure in regular F# coding. There are lots of use cases for this and it is easy enough to implement efficiently.
Fable and the Elmish design patterns are popularizing the use of immutable data for important model descriptions more and more and we should be helping improve the situation for that kind of programming.
The main question is to how to make on immutable array type normative in F# coding
We have decided it is acceptable for FSharp.Core to take a dependency on System.Collections.Immutable. We still want an FSharp.Core
module making it look and feel like a normal F# collection.
Expressions and patterns are extended with the syntax [: ... :] for block expressions and patterns.
The additions follow a standard FSharp.Core collection design:
namespace FSharp.Collections
...
type 'T immarray = System.Collections.Immutable.ImmutableArray<'T>
[<CompilationRepresentation(CompilationRepresentationFlags.ModuleSuffix)>]
[<RequireQualifiedAccess>]
module ImmArray =
let append(l1 : 'T immarray) (l2 : 'T immarray) = l1.AddRange(l2)
let empty<'T> = immarray<'T>.Empty
...etc. with the standard functions and values.
System.Collections.Immutable.ImmutableArray implements IStructuralEquality and IStructuralComparison, so
this means F# structural equality, hashing and comparison semantics are respected "all the way down".
TBD: examples and test cases
FSharp.Corehas a dependency onSystem.Collections.Immutable.dlland any transitive dependencies.
-
Don't do this and maintain status quo
-
Make a separate package
FSharp.Collections.Immutable.dll -
Use a different name
This is not a breaking change. The elaboration of existing code that passes type checking is not changed.
This doesn't extend the F# metadata format.
-
Full API design
-
Consider the extension property
IsEmpty.