就捕获而言,可变变量与引用变量
我对 f# 中变量的肤浅理解表明,将变量声明为“可变”并使用“ref”变量本质上都是做同样的事情。它们都是解决同一根本问题的不同方法——在函数式语言中对可变性进行有限且结构化的允许,而不必求助于 IO Monad。我的理解已经“抽象”了技术上的差异。
- 如果是这种情况,为什么闭包不能捕获可变变量,但它们可以捕获 ref 实例?
- 更一般地说,两种形式之间的技术差异是什么导致了这种差异?
- 从语言设计的角度来看,引入两个而不是一个可变性快捷方式的目的是什么?
如果这是一个多人参与的活动,我很抱歉,但它们似乎都是相关的。
My superficial understanding of variables in f# suggests that declaring a variable to be 'mutable' and using a 'ref' variable essentially both do the same thing. They are both different ways to address the same underlying issue - a limited and structured allowance of mutability in a functional language without having to resort to the IO Monad. That there is a technical different has been 'abstracted' by my understanding.
- If this is the case why can't closures capture mutable variables, but they can capture ref instances?
- More generally, what is the technical different between the two forms that allows this difference?
- What is the purpose from a language design point of view of introducing two mutability shortcuts rather than just one?
I'm sorry if this is a multi-parter, but they all seem related.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
请参阅
http://lorgonblog.wordpress.com/2008 /11/12/on-lambdas-capture-and-mutability/
特别是“语言设计评论”部分(我会在这里引用它,但它并不能很好地独立,您需要整个博客条目用于上下文)。
See
http://lorgonblog.wordpress.com/2008/11/12/on-lambdas-capture-and-mutability/
especially the "language design commentary" section (I'd quote it here, but it doesn't stand alone well, you need the whole blog entry for context).