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