aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2025-03-03 18:49:04 +0000
committerMichael Williamson <mike@zwobble.org>2025-03-03 18:49:04 +0000
commit6daa3023dc0a4b1bfe7b90f08ae0ee3358be579f (patch)
tree45542556128cb9ba52b1d50aa2831aca49576f09
parentc6005eba5727e711516ccc17fa64cf153a602260 (diff)
Add notes on explicit mutation
-rw-r--r--README.md20
1 files changed, 20 insertions, 0 deletions
diff --git a/README.md b/README.md
index b803d116..ec016979 100644
--- a/README.md
+++ b/README.md
@@ -51,3 +51,23 @@ var message = "hello, ";
set! message = message! + "world\n";
print!(message);
```
+
+Explicit heap / mutation context?
+
+```
+native type MutableArray[!M <: Mutate, T] {
+ native fun size(This) -> Int;
+
+ // Precondition: unsafeSet has previously been called with the same index.
+ native fun unsafeGet(This, Int) ! M -> T;
+
+ // Precondition: the index is in the range [0, size).
+ native fun unsafeSet(This, Int, T) ! M -> Unit;
+}
+```
+
+Issue: without linear types, no way of knowing whether there are multiple
+references to the mutable array, therefore building the array within a list
+builder requires either a new, immutable array to be constructed, or for the
+builder to mark its internal array as having been built, and therefore a copy
+should be created on the next append.