Caterpillar

Daily Thought - 2024-07-13

< back to list

I've been talking about linear types over the last few days, but I've kinda beaten around the bush on one topic: How do you eventually deal with a value of a linear type? You can't keep moving it somewhere else forever.

Let's look at an error, for example, that you received as a return value. You can pass it to another function, to handle it there. You can return it again, to have it handled by the caller. Or you can store it in a list, which means you'll be forced to handle the list eventually. But at some point, you need to deal with the value once and for all.

And you can do that by destructuring it, breaking it up into its component parts. (This is the thing that happens when you do pattern-matching in Rust, for example.) You could also make those component parts private, and force that destructuring to happen in the same module where the type is defined. Then the developer would have to call a function there, to handle the error.

<< previous thoughtnext thought >>