First, I acknowledge the possibility that this question could be a duplicate; just let me know.
I'm curious what the general "best practice" is for those situations when mutability is desired. F# seems to offer two facilities for this: the let mutable
binding, which seems to work like variables in "most" languages, and the reference cell (created with the ref
function) that requires explicit dereferencing to use.
There are a couple of cases where one is "forced" into one or the other: .NET interop tends to use mutable with <-
, and in workflow computations one must use ref
with :=
. So those cases are pretty clear-cut, but I'm curious what to do when creating my own mutable variables outside of those scenarios. What advantage does one style have over the other? (Perhaps further insight into the implementation would help.)
Thanks! (And sorry for "overuse" of quotation marks.)