4 ms·
> I.e. Rust right now is excellent at certain things ("linear things"), and okay at non-linear things. But could it be made to be really good for the latter too
by dan00 6y ago
> I.e. Rust right now is excellent at certain things ("linear things"), and okay at non-linear things. But could it be made to be really good for the latter too?
Having written programs in Rust and Haskell, which are in this regard
quite similar, I think that you can express most of your application in a
"linear" fashion and only have a bit of "non-linear" things at the top.
For example if you have to handle some "non-linear" things like events
from the system or a gui library, then you might have - in Rust
terminology - a 'RefCell<Rc<AppState>>' to be able to have shared mutable
access to the application state.
At the top of the event handler you would transform the
'RefCell<Rc<AppState>>' into a '&mut AppState', which is the switch
from the "non-linear world" to the "linear world" and involves a runtime
check that there's only one mutable reference. All the following code
of the handler can then be verified at compile time.
This also makes the reasoning about the application easier, because
you might even reduce the mutation of your application state to the
switching area. So most of the event handling could be a pure
transformation of the application state.
- nicoburns 6y agoI think Rust (or a new Rust-like language) could potentially be improved significantly by having language-level sugar for things like Rc<RefCell<T> Arc<Mutex<T>> or even some kind of Gc<T>.
- DougBTX 6y agoThere are experiments for a Gc<T> here: https://github.com/Manishearth/rust-gc https://github.com/Manishearth/rust-gc
- db48x 6y agoIf you find yourself wishing you didn't have to type some combination of types so often make a type alias. But the primary reason there's no built-in shortcut is that you might want to compose them in a different order.