3 ms·
Absolutely right, and it absolutely is immensely valuable. It's perfectly possible to do the same thing in a higher-level language though - if you only expose w
by lmm 10y ago
Absolutely right, and it absolutely is immensely valuable. It's perfectly possible to do the same thing in a higher-level language though - if you only expose with-file then you have the same safety guarantees as RAII. If you only expose composable commands and a way to execute them (i.e. a free monad approach - doobie is a good example) then you can get even better guarantees than are practical with RAII (there's no way to do the equivalent of "&myFile").
- catnaroek 10y ago`with-file` doesn't guarantee anything about users who forget to use it. With RAII, only the implementor needs to remember to use it, users can't “forget”, because there's nothing to remember. > It's perfectly possible to do the same thing in a higher-level language though - if you only expose with-file then you have the same safety guarantees as RAII. It's still less sophisticated than desirable. In Rust, objects can be moved to a different environment, so cleanup need not follow a strict LIFO discipline.