Daily Note - 2024-12-13
Hey, I'm Hanno! These are my daily notes on Crosscut, the programming language I'm creating. If you have any questions, comments, or feedback, please get in touch!
This note was published before Crosscut was called Crosscut! If it refers to "Caterpillar", that is the old name, just so you know.
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 Result
s. But as
effects go, they are more powerful.
Tomorrow, let's look into asynchrony, which is the most interesting one!