Crosscut

Daily Thought - 2024-12-20

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

Yesterday, I talked about the disadvantages of algebraic effects, starting with one that, in the context of Caterpillar, was rather easy to refute. Today, let's look at a problem that is giving me a bit more trouble: The interaction of effects with linear types.

Remember, linear types force you to use a value exactly once. Meaning you can't drop it implicitly, if it falls out of scope. This means you have to consider such a value, whenever you might trigger an effect.

file
    "a" write
    "b" write

Here we have a value that represents a file (currently bound to the name file), and write data to it twice. The write function would have a signature like File, Data -> File, meaning it would consume the data, but return the file again. That allows us to chain multiple calls, as I do here.

File would be a linear type, so Caterpillar can be purely functional. But write could trigger effects! One to signal the host, so it knows to actually write to the file. Another one, to signal that an error occurred while doing so. Tomorrow, I'd like to show how each presents a challenge for handling the linear type.

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