-
Notifications
You must be signed in to change notification settings - Fork 20
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
Mutable contents in Anonymous Records #732
Comments
Writing F# code you have to think a lot about the structures, i.e. types. Write down the type definitions, and the rest of the code often writes itself. For quick passing of data you can use tuples and now anonymous records without having to define these types in advance. So anonymous records serve the role of tuples but with named fields. Records with mutable fields don't fall into the category of passing around data. There must be a special purpose which required mutable fields. I believe this should be made clear with an explicit type definition. |
It feels like a sensible extension, adding to the parity with record types. Pondering if anonymous record with mutable fields can be consumed this way: let v = {| mutable field1 = 1 |}
let f (v: {| field1: int |}) = v.field1
f v Should this be allowed? |
Thank god I thought I was only one feeling that there was something missing: no latter than yesterday I was writing: let a = {| mutable Field1 = List.empty<int>
mutable Field2 = List.empty<int> |} And realized that it cannot compile awww Definitely +1 for this addition to the language |
I think this would be really helpful for Fable and TS2Fable. With this addition, many Typescript constructs can be represented as Anonymous Records. |
I don't like any After it put into a Hashset or Dictionary as key. Once the value is change,it's can never be found.
we can custom the record's equalizer to avoid it, but anonymous records how? |
I propose we allow for mutable contents in F# anonymous records. Today, it is not possible either as a declaration expression or when creating a new anonymous record:
(Note that the syntax in the screenshot is not necessarily what the syntax should be, it's just what felt the most natural to me)
Syntax could look like this:
This would be analogous to mutable contents in regular F# records.
The spec does not mention
mutable
labels, hence this suggestion.You can have a type be a
ref
cell today, so you can still mutate:However this does incur the additional allocation and readability costs of references cells.
Pros and Cons
The advantages of making this adjustment to F# are:
ref
cells if this is the pattern you're usingThe disadvantages of making this adjustment to F# are:
Extra information
Estimated cost (XS, S, M, L, XL, XXL): S-M
Affidavit (please submit!)
Please tick this by placing a cross in the box:
Please tick all that apply:
The text was updated successfully, but these errors were encountered: