3 ms·
Does Roc have escape hatches for mutability? That's something I value in Rust, good escape hatches from the borrow checker, so if something gets too difficult,
by hardwaregeek 2y ago
Does Roc have escape hatches for mutability? That's something I value in Rust, good escape hatches from the borrow checker, so if something gets too difficult, you can just `Arc<Mutex<RefCell<T>>>` it.
- eberfreitas 2y agoI don't think so (could be wrong), but it does perform optimistic mutation on your functional code. There is a talk somewhere where Richard "demos" this.
- hardwaregeek 2y agoyeah that seems cool! I'm a little skeptical of pure functional programming with no escape hatch. I rarely need the escapes in Rust but when I do, I really do.
- bhansconnect 2y agoIt isn't "no escape hatch". It is platform dependent escape hatches. A platform can give you full access to mutation and libffi if it wants.
- lalaithion 2y agoIt should be possible to have a platform that has a mutable reference with an API like this: main = x = pf.NewRef! pf.Write! x 5 y = pf.Read! x
- rtfeldman 2y agoThat's right, although the Rust equivalent of that would be more like `Future<Arc<Mutex<RefCell<T>>>>` than `Arc<Mutex<RefCell<T>>>` - so the ergonomics would be a bit different!
- greydius 2y agoHaskell: import Data.IORef main :: IO () main = do x <- newIORef (0 :: Int) writeIORef x 5 y <- readIORef x print y