Daily Thought - 2024-12-23
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.
Dealing with a single linear value in the presence of an Error
effect is, it
seems, a solvable issue. But what if you have multiple
linear values, only one of which is involved in possibly triggering a given
instance of the Error
effect?
Let's look at another example:
file_a "a" write
file_b "b" write
Two files, and we're writing to each of them. But this can't work as written. If
writing to file_a
triggers Error
, then the write
function (which triggers
the effect) can make sure that file_a
is put into the error, and whoever ends
up handling the effect can dispose of the file accordingly. But that instance of
write
doesn't know about file_b
, so what happens to that?
The compiler must reject this code, but it could be made to work like this:
try
file_a "a" write
handle Error(file_a)
Error(file_a, file_b) trigger
end
try
file_b "b" write
handle Error(file_b)
Error(file_a, file_b) trigger
end
(This is just some example effect handling syntax I invented right now. If anything like this makes its way into the language, it would most likely go through more revisions.)
Here, we handle the Error
effect for each call to write
, and pass it on, but
with the second file value added. This solves the immediate problem, but is way
too verbose.
Maybe we could invent some clever API that does this for us. Or maybe there could be some kind of implicit rule, that every effect gets automatically transformed by every scope it goes through, with all the linear values being added to it. Then the initial example would just work. But that sounds quite complicated, and too magical to easily understand.
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.