mirror of
https://github.com/adambard/learnxinyminutes-docs.git
synced 2024-12-23 17:41:41 +00:00
[F#/en] added mutation (#4763)
This commit is contained in:
parent
665c28c90e
commit
51efc47933
@ -33,6 +33,21 @@ let myInt = 5
|
||||
let myFloat = 3.14
|
||||
let myString = "hello" // note that no types needed
|
||||
|
||||
// Mutable variables
|
||||
let mutable a=3
|
||||
a <- 4 // a is now 4.
|
||||
|
||||
// Somewhat mutable variables
|
||||
// Reference cells are storage locations that enable you to create mutable values with reference semantics.
|
||||
// See https://learn.microsoft.com/en-us/dotnet/fsharp/language-reference/reference-cells
|
||||
let xRef = ref 10
|
||||
printfn "%d" xRef.Value // 10
|
||||
xRef.Value <- 11
|
||||
printfn "%d" xRef.Value // 11
|
||||
|
||||
let a=[ref 0; ref 1] // somewhat mutable list
|
||||
a[0].Value <- 2
|
||||
|
||||
// ------ Lists ------
|
||||
let twoToFive = [2; 3; 4; 5] // Square brackets create a list with
|
||||
// semicolon delimiters.
|
||||
|
Loading…
Reference in New Issue
Block a user