4 ms·
2 would be a kind of explicit destructors/drop ?
by ithkuil 4y ago
2 would be a kind of explicit destructors/drop ?
- pjmlp 4y agoSomething like this fictional language, with-some-resource { res -> // use res as you like } The with-some-resource function takes care of the resource management, while the type system takes care res doesn't escape the lambda.
- ithkuil 4y agoWhat if you want to move the ownership of the resource and let the new owner eventually to dispose it?
- whateveracct 4y agoThen withX isn't the right abstraction. The original situation (malloc gives you a linear variable) handles what you want. A function that takes the variable but does not return it effectively "takes ownership of it" and the type system will force a free. There's a "Linear Constraints" paper draft out there that emulates ownership and borrowing with linear types, and uses the titular new language feature to greatly improve ergonomics.