Caterpillar

Daily Thought - 2024-12-13

< back to list

Effects are a thing in every language. But if they are ad-hoc, with no principled effect system, that can cause problems. Let's understand this a bit better, by looking at Rust again. I want to explore three effects: Asynchrony, panics, and errors. Let's start with that last one, because it is the simplest.

A function can return a Result. That contains either the actual return value, or an error. I introduced effects as something that interrupts the code that triggers it, allowing a handler to decide what to do. This is a very limited form of that, where the handler is always the caller of the function, and resuming the function is not an option.

Panics are a bit less limited. Here, we use a kind of side channel (instead of the return value) to transport the error, and the handler can be anywhere up the call chain. There's still no way to resume though. Panics in Rust are somewhat problematic, and usually less suited for error handling than Results. But as effects go, they are more powerful.

Tomorrow, let's look into asynchrony, which is the most interesting one!

<< previous thoughtnext thought >>

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.