3 ms·
> you can not get referential transparency with mutable variables Sure you can: https://homepages.inf.ed.ac.uk/wadler/topics/linear-logic.html#linear-types htt
by zenhack 7y ago
> you can not get referential transparency with mutable variables
Sure you can: https://homepages.inf.ed.ac.uk/wadler/topics/linear-logic.html#linear-types https://homepages.inf.ed.ac.uk/wadler/topics/linear-logic.ht...
Rust's ownership types and lifetimes actually allow for this just fine. The latter is the essence of how Haskell's ST Monad works; you can use lifetimes to get locally-mutable state without violating global invariants, since once they go out of scope they can't be reused.
It's interesting to observe that, without "magic" standard library functions and `unsafe`, Rust's type system actually completely constrains mutability, and if a function doesn't have `mut` somewhere in its type signature, it doesn't break referential transparency.
That said, in practice, the language does have magic functions that violate this property, and they do so in a way that means you can't use the above reasoning principle at all. Also, mutability being constrained by the types is not the same thing as typical code not using it everywhere, which is the situation with rust-as-found.