r/ProgrammingLanguages • u/RishabhRD • 18d ago
Safe Systems-programming with Mutable Value Semantics | Dave Abrahams | Keynote at IWACO 2026
https://youtu.be/op51SyyPJmw?si=P5QH6M8Hdf4_CUUZ
33
Upvotes
View all comments
Show parent comment
2
u/processeus1 16d ago
Great examples, thanks a lot for the thoughts!
> Indexing-like operations that might fail: index_at(inout Container, let Index) -> Optional<inout Value>
If the operation might not yield an element, then instead of wrapping the reference into an optional, we can just simply not yield anything. We can extend the subscript ABI with a boolean flag that indicates whether the callee yielded anything, and we can require the caller to pattern match that if they want to use the result.
```hylo
subscript min(a: inout Int, b: inout Int) inout? -> Int {
if a < b { yield &a }
else if b < a { yield &b }
}
fun main() {
var (a, b) = (1, 3)
if let m ?= min[&a, &b] {
&m += 1
} // else no value yielded
print(a, b)
}
```
> Failable operations that might return projections: append_within_capacity(inout ArrayList<T>, sink T) -> Result<inout T, sink T>
This is pretty interesting, and I don't immediately see a better way to handle that than asking the function to move the object into the returned result. `sink` in, independently stored value out. Otherwise, you have to introduce lifetime dependencies and things get complicated. Do you have use cases where moving the result would be inappropriate?
> - Generalized slices: split_at_inout(inout ArrayList<T>, at_index: Int) -> Pair<ListSlice<T, inout>>
> - Map entries returned from map data structure subscripts and map iterators need to be able to have stored projections: KeyValuePair<let K, inout V>
These are both examples of yielding more than one elements at once. We were thinking of allowing to yield a tuple of projections. We should be careful though, because unless we do something special, yielding the tuple `{T, U}` would look just like yielding a single object-a whole, so we would either need to mark the elements as remote parts (value-semantic references), or indicate that this is not a regular tuple but a tuple of projections. The latter version I could by not having a special tuple in the type system, just part of the signature of a function/subscript - The same way a function can have multiple parameters with different conventions, it should be possible to have a subscript with a list of yielded bindings:
A dummy example:
```hylo
subscript entry<K, V>(xs: inout ArrayList<K, V>, at key: K) -> let K, inout V {
let i = xs.keys(key)
inout v = xs.values[i]
yield k, &v
}
```
> Any kind of iterators and iterator-adapters
As far as I know, index based APIs can go pretty far, but these are I think the most challenging to design. u/RishabhRD, could you summarize our ongoing designs or link some discussions on this topic?