fsharp / fslang-suggestions

The place to make suggestions, discuss and vote on F# language and core library features
346 stars 21 forks source link

Assigning many mutables when deconstructing tuples #1269

Open dark-valkyrix opened 1 year ago

dark-valkyrix commented 1 year ago

I propose we allow multiple mutable assignments when deconstructing tuples :

let mutable a = 0
let mutable b = 0
let mutable c = 0

(a, b, c) <- (1, 2, 3)

is currently not allowed.

The existing way of approaching this problem in F# is by using single mutable assignments :

let mutable a = 0
let mutable b = 0
let mutable c = 0

a <- 1
b <- 2
c <- 3

Pros and Cons

The advantages of making this adjustment to F# are more concise code.

The disadvantages of making this adjustment to F# are abusing of mutable variables.

Extra information

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

Related suggestions: (put links to related suggestions here)

Affidavit (please submit!)

Please tick this by placing a cross in the box:

Please tick all that apply:

For Readers

If you would like to see this issue implemented, please click the :+1: emoji on this issue. These counts are used to generally order the suggestions by engagement.

charlesroddie commented 1 year ago

Close as duplicate of https://github.com/fsharp/fslang-suggestions/issues/1011

BentTranberg commented 1 year ago

I believe the intention is that all three boxes below the headline "Affidavit" is checked before an issue is submitted. As it says in the Code tab: Just use GitHub search over the issues in this repository. It can still happen that we get a duplicate, but then we've at least made the effort intended to decrease the number of issues.

dark-valkyrix commented 1 year ago

Close as duplicate of #1011

Sorry, it might look similar to you, it does not to me. This has nothing to do with classes. I understood such complexity might have led the answer to be a "no".

I suggest the opposite then, for more consistency, how about we forbid ?

let (a, b, c) = (1, 2, 3)

That way, we don't ask for :

let mutable (a, b, c) <- (1, 2, 3)
jwosty commented 1 year ago

@dark-valkyrix These really are the same suggestion at the core. I doubt that Don rejected it because of the usage of a class in the example; I think he doesn't want the idea itself. I do understand the desire for such symmetry (and I personally wouldn't think it would be so terrible), but it's already been decided.

Disallowing tuple patterns from regular let-bindings would not be in any way feasible, as that would be an unbelievably breaking change.