Maybe it\'s too simple thing to do, but I can\'t find any answer in the web
I\'m try to Increment value in F# (like count++
in C#).
I don\'t want to use
If you don't want to use mutable then you can't really do a destructive update like ++
is in C#. You could shadow a variable with a new one with the same name e.g.
let x = 4;
let x = x + 1 in (x+4) //returns 8
although you couldn't write this as a function.
EDIT: If do want to use mutable variables then you can create a function which modifies a ref:
let increment (ir: int ref) = ir := !ir + 1
You can then use it as
let i = ref 1
increment i
let iv = !i //iv contains 2
As Tomas points out in his answer, this function already exists and is called incr
.