References provide a way to share data between instances and to define recursive data types that would otherwise be infinitely large.
A List using references
Here is a small example that defines a feature
Node that contains
String and an optional
tail that is itself
When trying to compile this, we get an error due to cyclic types:
Node may not contain itself, so the object layout fails.
A solution is to declare
Node to be a
ref, i.e., any
field of type
Node will not contain a
directly, but only refer to a
Node. Now the code compiles and runs:
A reference value of a given feature type
f can be assigned to a
reference field whose type is a reference to
f or, recursively, any
of features called in
f's inherits clause.
Assigning value instances to references
This should automatically create a reference to the instance (if it is immutable and has a lifespan that exceeds that of the reference) or a copy of the instance.
Assigning reference to value fields
It must be decided if this should be allowed at all, my preference is to forbid it since the dynamic binding gets lost and the resulting behavior may be wrong.