I propose we allow any pattern binding to be mutable.
let f (mutable d : System.Collections.Generic.Dictionary<int, int>) = // mutable parameter bindings
for KeyValue (mutable k, mutable v) in d do
// use k and v in an imperative algorithm...
v <- v + 1
The existing let mutable x = syntax is equivalent to let (mutable x) =. Self identifiers should not be allowed mutable to be consistent with C#.
The existing way of approaching this problem in F# is to do an explicit copy.
let f (d : System.Collections.Generic.Dictionary<int, int>) =
let mutable d = d // here
for KeyValue (k, v) in d do
let mutable k = k // here
let mutable v = v // here
// use k and v in an imperative algorithm...
v <- v + 1
This is undesirable for large structs which could have avoided an unnecessary copy.
Pros and Cons
The advantages of making this adjustment to F# are
- Less boilerplate
- More optimization opportunities
The disadvantage of making this adjustment to F# is the encouragement of using mutables in a functional programming language. However, F# is multi-paradigm, and we use imperative programming where suitable, right?
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:
Please tick all that apply:
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.
I propose we allow any pattern binding to be mutable.
The existing
let mutable x =syntax is equivalent tolet (mutable x) =. Self identifiers should not be allowedmutableto be consistent with C#.The existing way of approaching this problem in F# is to do an explicit copy.
This is undesirable for large structs which could have avoided an unnecessary copy.
Pros and Cons
The advantages of making this adjustment to F# are
The disadvantage of making this adjustment to F# is the encouragement of using mutables in a functional programming language. However, F# is multi-paradigm, and we use imperative programming where suitable, right?
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:
Please tick all that apply:
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.