Daily Thought - 2024-12-15
< back to listOver the last few days, we've looked at several of the ad-hoc effects in Rust.
First Result
and panics, then
asynchrony. Armed with that knowledge, we can now imagine a
unified system that includes the most powerful aspects of all of them, and can
support any kind of effect.
Here's what such a unified system could include:
- It would use a side channel to transport effects, instead of return values. The caller doesn't have to know about the effect, and a handler can sit anywhere in the call chain.
- Handlers themselves can trigger the effect (or any other), allowing for nested handlers that can make a decision at their respective level.
- Any code that triggers an effect can be resumed afterwards, if the handler decides it's appropriate.
A language that has such a system, could use it to provide all kinds of effects.
The ones I already mentioned, but also I/O could be covered by effects.
Randomness could be, making it easy to control where that's important (think
multiplayer games). In Rust, unsafe
could be one! Imagine using that to easily
sandbox any dependency you don't trust.
Hey, you! Want to subscribe to my daily thoughts? Just let me know (maybe include a nice message, if you're up for it), and I'll send you an email whenever I post a new one.