开发者

Mutable vs Ref variables in terms of capture

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.

  1. If this is the case why can't closures capture mutable variables, but they can capture ref instances?
  2. More generally, what is the technical different between the two forms that allows this difference?
  3. What is the purpose f开发者_如何学Gorom 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.


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).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜