Is there any functional difference between immutable value types and immutable reference types?
- by Kendall Frey
Value types are types which do not have an identity. When one variable is modified, other instances are not.
Using Javascript syntax as an example, here is how a value type works.
var foo = { a: 42 };
var bar = foo;
bar.a = 0;
// foo.a is still 42
Reference types are types which do have an identity. When one variable is modified, other instances are as well.
Here is how a reference type works.
var foo = { a: 42 };
var bar = foo;
bar.a = 0;
// foo.a is now 0
Note how the example uses mutatable objects to show the difference. If the objects were immutable, you couldn't do that, so that kind of testing for value/reference types doesn't work.
Is there any functional difference between immutable value types and immutable reference types? Is there any algorithm that can tell the difference between a reference type and a value type if they are immutable? Reflection is cheating.
I'm wondering this mostly out of curiosity.