Explaining mutability and immutability

Once a variable is defined to have a particular value, it keeps that value indefinitely. There are exceptions to this, and shadowing can be used to override a previous assignment made within the same scope. Thus, variables in mathematics are immutable. Similarly, variables in F# are immutable with some exceptions.

Immutable variables are default in F#. They are useful because they are thread-safe and easier to reason about. This is one of the reasons you may have heard a lot about immutability recently. The concept is to solve the biggest issues and design flaws of concurrent programming, including shared mutable state. If the values do not change, there is no need to protect them either, which is one of the ...

Get F# for Quantitative Finance now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.