Crosscut

Daily Thought - 2024-08-14

Hey, I'm Hanno! These are my daily thoughts on Crosscut, the programming language I'm creating. If you have any questions, comments, or feedback, please get in touch!

This thought was published before Crosscut was called Crosscut! If it refers to "Caterpillar", that is the old name, just so you know.

< back to list

So what were the problems with if that led me to pattern matching? There are two: Call stack reconstruction and linear types. Let's start with linear types, because to get to call stack reconstruction, we need more background.

Okay, so a value of a linear type can only be used once, meaning if we want to use it in a closure, the closure needs to take ownership. That means we can't have two closures using the same value. (If the value is of a linear type. Not all types have to be linear.)

So if we model if as a built-in function with two closure parameters, then both can't take ownership of the same linear value. It would be fine in principle, because only one of them gets executed, but the compiler doesn't know that. To the compiler, a built-in function is opaque.

<< 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.