I remember the moment when I learned about immutability. It changed everything. — Denis Defreyne Periodically, in various programming language forums, the discussion comes up of why a certain language doesn’t provide the immutable and mutable variants of some data structure as subtypes or supertypes of one another. Now, it’s not impossible to do this, but it’s actually not formally correct to do so, and by doing so you’ll lose at least some of the type checking guarantees your language can usually make for you. To understand why this doesn’t work, you have to remember the definition of a subtype. Namely, Liskov’s subsitution principle : a type S is a subtype of T if a value of type S can be used in every context where a value of type T is expected. As usual when dealing with formal matters, this definition is strictly interpreted. Every really does mean every , not just most .…