Open eladb opened 1 year ago
explicit immutability shit
Related: https://github.com/winglang/wing/issues/64
We would need some mechanism to determine whether something like this is type-safe (inflight-safe) or not:
bring "my-restaurant" as my_restaurant;
let order = new my_restaurant.Order();
orders.addFood("hummus");
new cloud.Function(inflight (m: str): str => {
print(order.to_str());
});
orders.addFood("pita"); // mutation bad! 👻
👍
@Chriscbr in your example it is not even telling the compiler that order
is immutable, it is telling it that it is immutable from a certain point, which makes me think if we don't want to add this mechanism for language structures as well (for instance Set).
If the answer is no for language structures then I think it should also be no for other objects.
In this case, assuming we add a freeze
keyword, your example will look something like this:
bring "my-restaurant" as my_restaurant;
let order = new my_restaurant.Order();
order.addFood("hummus");
let changed_order = freeze deepClone(order);
new cloud.Function(inflight (m: str): str => {
print(changed_order.to_str());
});
order.addFood("pita"); // mutation allowed :)
changed_order.addFood("pita"); // mutation bad! 👻
A freeze
keyword is a neat idea
Hi,
This issue hasn't seen activity in 60 days. Therefore, we are marking this issue as stale for now. It will be closed after 7 days. Feel free to re-open this issue when there's an update or relevant information to be added. Thanks!
Keep
Hi,
This issue hasn't seen activity in 60 days. Therefore, we are marking this issue as stale for now. It will be closed after 7 days. Feel free to re-open this issue when there's an update or relevant information to be added. Thanks!
Hi,
This issue hasn't seen activity in 90 days. Therefore, we are marking this issue as stale for now. It will be closed after 7 days. Feel free to re-open this issue when there's an update or relevant information to be added. Thanks!
Community Note
Feature Spec
It is now possible to somehow tell the Wing compiler that user-defined classes can be captured safely.
This means we need some explicit immutability shit.
Use Cases
Be able to capture user-defined types
Implementation Notes
No response
Component
No response