Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
i have seen in ruby as well powershell programming we can assign variables like a,b=b,a . it actually swaps the variable .
Is this possible in f# if so please guide me with some reference
通常,F# 不允许变量重新分配。相反,它通过 let 绑定支持不可变的命名值。因此,以下是不可能的:
let a = 3 a = 4
除非您明确标记a为mutable:
a
mutable
let mutable a = 3 a <- 4
然而,在大多数情况下,F# 确实允许变量“遮蔽”。对此的唯一限制是它不能在顶级模块上完成。但是,在一个函数中,例如,以下工作正常:
let f () = let a,b = 1,2 let a,b = b,a //"swap" a,b