3 ms·
RAII works as long as you don't have closures, which are prevalent in higher-order/functional settings. If I adhere to RAII, I guarantee that if I allocate som
by mrkeen 7y ago
RAII works as long as you don't have closures, which are prevalent in higher-order/functional settings.
If I adhere to RAII, I guarantee that if I allocate something in a scope then it will be de-allocated when I leave the scope. But if I want to return a closure (a function pointer + state) then I can't de-allocate it myself.
I thing C++ and Rust are trying to address this kind of thing with move semantics and ownership. Perhaps functional languages will solve this kind of thing with linear types in the future.
I'm currently looking into 'defunctionalization', 'lambda lifting', etc. to see if they are viable alternatives.
- thesz 7y agohttps://en.wikipedia.org/wiki/Region-based_memory_management#Region_inference https://en.wikipedia.org/wiki/Region-based_memory_management... You can infer where you should allocate data. It was done 25 years ago. The problem is that for complex programs you end with one big region and this is not useful. Linear types that are visible to the user will not solve these problems. In fact, they will complicate things greatly, because you have to provide two functions for mapping, for example: for normal and linear types. And their mix with normal types is problematic at best. The inference of linear operations in the backend, on the other hand, can be more efficient - you may end up using linear memory references not knowing about that.