F #
// The following Code demonstrates the use of reference // Cells to enable partially applied arguments to be changed // By Later code. Let Increment1 delta number = Number + Delta Let Mutable Mymutableincrement = 10 // Closures created by partial application and literals. Let Incrementby1 = increment1 1 Let Incrementby2 = increment1 2 // Partial application of one argument from a mutable variable. Let Incrementmutable = increment1 mymutableincrementmymutableincrement <-12 // This line prints 110. Printfn "% D" (Incrementmutable 100) Let Myrefincrement = Ref 10 // Partial application of one argument, dereferenced // From a reference cell. Let Incrementref = increment1! Myrefincrementmyrefincrement: = 12 // This line also prints 110. Printfn "% D" (Incrementref 100)// Reset the value of the reference cell. Myrefincrement: = 10 // New increment function takes a reference cell. Let Increment2 delta number = Number +! Delta // Partial application of one argument, passing a reference Cell // Without dereferencing first. Let Incrementref2 = increment2 myrefincrementmyrefincrement: = 12 // This line prints 112. Printfn "% D" (Incrementref2100)
-----------------
Let mutable x = 1let x' = XX <-2x '(OR 1, it copies x, so it will not be changed by X)