Caterpillar

Daily Thought - 2024-07-09

< back to list

I've mentioned linear types before, in the context of representing I/O resources as values. In a linear type system, values can be used exactly once. This would be an error:

value do_thing
value do_other_thing # error! already used `value`

So far this is similar to Rust's type system, which uses affine types. With affine types, values can be used at most once, meaning they can also be used zero times. This is not possible with linear types:

make_value => value {
    # error! not using `value`
}

Being forced to use every value, means that errors need to be handled, files need to be closed, etc. And this is enforced at compile-time, so you won't forget.

<< previous thoughtnext thought >>