Assignment operator in f#

て烟熏妆下的殇ゞ 提交于 2019-11-28 12:38:18

Generally, F# doesn't allow variable re-assignment. Rather it favors immutable named values via let 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# does allow in most situations variable "shadowing". The only restriction to this is that it can not be done on top level modules. But, within a function, for example, the following works fine:

let f () =
    let a,b = 1,2
    let a,b = b,a //"swap"
    a,b
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!