News for hackers. Stuff that matters.
Re:Copying data is wasteful, mutating data is dangerous by hderms on Thursday January 09, 2020 @12:56PM (#22003611)
Imo you have to allocate something else if you are going with an immutable paradigm. You can do clever sharing of data structures, but ultimately if you're modifying the whole thing, you're modifying the whole thing and sharing can only go so far. It seems like further advances in this space either require giving the compiler a better understanding of what is "actually" shared and in what way (i.e. Rust and knowing when mutations are externally visible), or making copying cheaper.

Mutability is always (at least as current computer architectures are concerned) going to be faster in a general sense.

Re:Copying data is wasteful, mutating data is dangerous by tene on Thursday January 09, 2020 @07:59PM (#22007569)
You may be interested in the `im` crate for Rust, which implements efficient copy-on-write structural sharing, falling back to in-place mutation when there are no other outstanding references.

https://docs.rs/im/14.1.0/im/

Re:Copying data is wasteful, mutating data is dangerous by vmchale on Thursday January 09, 2020 @02:03PM (#22004303)
> It seems like further advances in this space either require giving the compiler a better understanding of what is "actually" shared

In the context of arrays, it helps when programmers use higher-order combinators/functions, e.g. maps.

There is a mutable way to do a map, and an immutable way, and which should be used in the compiled program depends on analysis of where the variable is used.