-
Notifications
You must be signed in to change notification settings - Fork 22
Description
The Array2D module is designed around allowing for non-zero-based Array2Ds. This is very unusual in the following ways:
- It is not the case for the Array, Array3D, and Array4D modules. E.g. for Array: "Arrays are fixed-size, zero-based, mutable collections...". So it's an odd one out.
- It is unusual in dotnet, and C# does not have syntax for creating non-zero-based Array2Ds, or a normal constructor.
- It is also very unusual in F#. A github search for Array2D.initBased brings up 101 files, compared to 2.6k for Array2D.init, and almost all the examples are documentation or copies of the F# module, the exceptions being teaching code like advent of code or exercism.
This causes problems in F# code in that most Array2D module functions need to allow for the possibility of arrays being non-zero-based, and so may end up calling Array2D.initBased, and this uses a non-trim-safe method (Array.CreateInstance(typeof<'T>, [|length1;length2|], [|base1;base2|]) :?> 'T[,]) which has RequiresDynamicCodeAttribute. This results in trim warnings for F# code using Array2D functions.
It also has caused random bugs in our app in the past in ways that are platform dependent (e.g. we had an Android bug with System.MethodAccessException from Array2DModule.InitializeBased[SkViews.Table.Cell] resulting from normal use of a private type.
I propose we deprecate non-zero-based Array2Ds as an anomaly.
This would involve:
- Mark zeroCreateBased, createBased, initBased, rebase as deprecated
- Fail other methods if bases are non-zero
The existing way of approaching this problem in F# is ...
Avoid the trim issues by avoiding the FSharp.Core module and defining another zero-based module for Array2D.
Pros and Cons
The advantages of making this adjustment to F# are ...
Consistency between Array2D and Array, Array3D and Array4D.
Avoiding allowing users to create things that are not expected in dotnet.
The disadvantages of making this adjustment to F# are ...
A small amount of existing code using the based methods would need to be migrated away or would need to make copies of old methods.
Extra information
Estimated cost (XS, S, M, L, XL, XXL):
S
Related suggestions: (put links to related suggestions here)
Affidavit (please submit!)
Please tick these items by placing a cross in the box:
- [ x ] This is not a question (e.g. like one you might ask on StackOverflow) and I have searched StackOverflow for discussions of this issue
- [ x ] This is a language change and not purely a tooling change (e.g. compiler bug, editor support, warning/error messages, new warning, non-breaking optimisation) belonging to the compiler and tooling repository
- [ 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
- [ x ] I have searched both open and closed suggestions on this site and believe this is not a duplicate
Please tick all that apply:
- 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
For Readers
If you would like to see this issue implemented, please click the 👍 emoji on this issue. These counts are used to generally order the suggestions by engagement.