-
Notifications
You must be signed in to change notification settings - Fork 53
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Better control over immutability #189
Comments
Give we are replacing freeze with readOnlyClone (see #186), the right keyword will be |
Do we also need to say for a parameter that the immutability of the result comes from the immutability of an a parameter? |
We would want the values of annotations to be constructed as immutable. |
Immutability proposal also related to #189.
I have created issues for parts of this, so we can stage the change: |
I separated the part of this relating to objects into #469. |
The goals are:
Note that we can already do the above for compile-time constants. The goal here is to extend this to values that are not known at runtime.
It is not a goal to guarantee at compile-time that immutable values are not written to. Some instances of this are caught at compile-time, but in general this is enforced at runtime. This is consistent with the overall design of the type system which guarantees that reads succeed and are type-safe, but does not make the same guarantee for writes. It is also consistent with what we do with
const
.This could work as follows.
immutable
:anydata|error
<immutable>
We could also use
readonly
instead ofimmutable
.Note that this does not allow types to be declared immutable, nor fields of records/objects.
Semantics are as follows:
return E
the contextually expected mutability of E would come from the declared mutability of the return type of the functionE is immutable
To explain this, it would help to have a word that means type (in the sense of shape) together with immutability. This could be called “type”, where type has two aspects, which are shape and immutability. However that does not fit with how we are already using the keyword “type” to describe just the shape aspect of type.
This is the second part of #186. It also relates to #145.
The text was updated successfully, but these errors were encountered: