Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create FS-1094-block.md #526

Merged
merged 1 commit into from
Jan 21, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 79 additions & 0 deletions RFCs/FS-1094-block.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
# F# RFC FS-1093 - Block for ImmutableArray

The design suggestion [A normative immutable array type](https://github.com/fsharp/fslang-suggestions/issues/619) 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 TBD

# Summary

A new collection type `'T block` will be added to FSharp.Core, and FSharp.Core will now be dependent on System.Collections.Immutable

# Motivation

Prior to this RFCS 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.


# Detailed design

```fsharp
namespace FSharp.Collections

...

type 'T block = System.Collections.Immutable.ImmutableArray<'T>

[<CompilationRepresentation(CompilationRepresentationFlags.ModuleSuffix)>]
[<RequireQualifiedAccess>]
module Block =

let append(l1 : 'T block) (l2 : 'T block) = l1.AddRange(l2)

let empty<'T> = block<'T>.Empty
...
```

etc. with the standard interface.

### Structural equality, hashing and comparison

`System.Collections.Immutable.ImmutableArray` implements `IStructuralEquality` and `IStructuralComparison`, so
this means F# strucural equality, hashing and comparison semantics are respected "all the way down".

TBD: examples and test cases


# Drawbacks

* `FSharp.Core` has a dependency on `System.Collections.Immutable.dll` and any transitive dependencies.


# Alternatives

- Don't do this and maintain status quo

- Make a separate package `FSharp.Cllections.Block.dll`

- Use a different name

# Compatibility

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.

# Unresolved questions

* Full API design