【发布时间】:2013-04-17 03:52:50
【问题描述】:
可能是另一个愚蠢的 F# 初学者问题......但它仍然困扰着我
我似乎无法在网上找到任何答案...可能是因为我搜索了错误的术语,但是嗯
反正我的代码如下:
let counter() =
let mutable x = 0
let increment(y :int) =
x <- x + y // this line is giving me trouble
printfn "%A" x // and this one too
increment // return the function
Visual Studio 告诉我 x 的使用方式无效,闭包无法捕获可变变量
这是为什么呢?我该怎么做才能让我变异它?
【问题讨论】:
标签: function variables f# mutable mutation