@gvwilson Wouldn‘t an „Iterator“ type fit that description? A couple of languages have those.
Swift has a few more types that go in that direction of „how it‘s used“ but often not on the same level of simplicity as in Sajaniemi‘s variable roles.
Here are some that I think go in that direction and that exist in Swift:
- Sequence and Collection: protocols in Swift
- ~Copyable: a value that cannot be copied, so a move-only type: only one object can hold onto it at a time
- Mutex: used to wrap other values in it, to prevent concurrent access/modification of the wrapped value in a concurrent program
- actor: a keyword-level type in Swift. Used to protect state and then „act“ on it in a concurrency-safe manner. Some parallels to Mutex, but a lot more complexity around it. Ensures modifications to the state are serialized (instead of happening concurrently) but doesn‘t block like a Mutex.
- the `let` keyword basically captures the „fixed value“ concept. However there are subtle differences between using it for value types and for reference types.
- the Result type holds the result of a computation that may have gone wrong