Skip to content

mutable fields in Structs are not described #9563

@Szer

Description

@Szer

Documentation lacks examples of
val mutable fields and way of their mutation without implicit copying of structure.

[<Struct>]
type Foo = 
  val mutable bar: string
  member self.ChangeBar bar = self.bar <- bar
  new (bar) = {bar = bar}

let foo = Foo "1"
foo.ChangeBar "2" //make implicit copy of Foo, changes the copy, discards the copy, foo remains unchanged
printfn "%s" foo.bar //prints 1

let mutable foo' = Foo "1"
foo'.ChangeBar "2" //changes foo'
printfn "%s" foo'.bar //prints 2

Document Details

Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions