Assignment operator in f #

I have seen in ruby, as well as programming using the shell, we can assign variables like a, b = b, a . it actually changes the variable.

Is this possible in f #, if so, please help me with some link

+4
source share
1 answer

Typically, F # does not allow a variable to be reset. Rather, it supports immutable named values ​​through bindings. So the following is not possible:

let a = 3 a = 4 

Unless you explicitly mark a as mutable :

 let mutable a = 3 a <- 4 

However, F # resolves the shading variable in most situations. The only restriction on this is that it cannot be done on top-level modules. But, within the function, for example, the following works fine:

 let f () = let a,b = 1,2 let a,b = b,a //"swap" a,b 
+13
source

Source: https://habr.com/ru/post/1346500/


All Articles