fsharp / fsharp/fslang-suggestions

A normative immutable array type

Open
#619 261 comments 43 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

approved-in-principle area: library area: lists-arrays-sequences needs rfc
Dominant language
No language data
Stars
373
Forks
21
PR merge metrics
No merged PRs in 30d

Description

For people coming to this thread afresh, the RFC is here: https://github.com/fsharp/fslang-design/blob/main/RFCs/FS-1094-immarray.md
----

I propose we work out how to make one particular immutable array type normative in F# programming "in the box", including in Fable programming.

The existing way of approaching this problem in F# is to use a user-supplied package of collections such ``System.Collections.Immutable``

## Description

One particular thing that is a hole in our library is the lack of 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, e.g. [here](https://github.com/fsprojects/FSharpx.Collections/blob/master/src/FSharpx.Collections.Experimental/FlatList.fs) (originally from the compiler codebase) though there are other approaches.

I’m particularly aware that Fable and the Elmish design pattern is 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

1. Add a bespoke immutable array to FSharp.Core.

2. Encourage people to take a dependency on System.Collections.Immutable and add a reference to it to our standard templates. However we would still presumably want an FSharp.Core module making it look and feel like a normal F# collection, but we wouldn't want FSharp.Core to have a dependency on System.Collections.Immutable.

Probably the hardest thing is to decide its name.
* ``ImmutableArray`` is too long, especially for a module
* ``IArray`` looks like an interface
* ``FlatList`` breaks with industry naming, it looks too odd.
* ``XArray``, ``ZArray`` are possible if we are desperate – e.g. just make a new F# convention that ``ZThing`` is an immutable version of ``Thing``
* ``Block`` wins the day

Related questions are
1. Would want a bespoke functional update syntax “{ arr with 3 = expr }” or “{ arr with n = expr } or “arr.[n=expr]”.
2. Would the type feel right from F# code – good ergonomics etc
3. What library dependencies would the type induce
4. How do other collections from System.Collections.Immutable feel to use from F#?

## Extra information

Estimated cost (XS, S, M, L, XL, XXL): M

## Affidavit (please submit!)

Please tick this by placing a cross in the box:
* [x] This is not a question (e.g. like one you might ask on [stackoverflow](http://stackoverflow.com)) and I have searched stackoverflow for discussions of this issue
* [x] I have [searched both open and closed suggestions on this site](http://github.com/fsharp/fslang-suggestions/issues) and believe this is not a duplicate
* [x] This is not something which has obviously "already been decided" in previous versions of F#. If you're questioning a fundamental design decision that has obviously already been taken (e.g. "Make F# untyped") then please don't submit it.

Please tick all that apply:
* [x] This is not a breaking change to the F# language design
* [x] I or my company would be willing to help implement and/or test this

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the linked RFC FS-1094-immarray.md, then compare the proposed approaches with System.Collections.Immutable and the referenced FSharpx.Collections FlatList.fs implementation. Done means reaching an accepted design for the normative immutable array, including its name, dependencies, update syntax, and F# ergonomics.

Written by the indexing model from the issue text.

Assessment

Tech stack
fsharp
Domain
compilers
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
20/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.