News for hackers. Stuff that matters.
Re:Copying data is wasteful, mutating data is dangerous by mrkeen on Thursday January 09, 2020 @03:12PM (#22005131)
I'm surprised no-one has mentioned Haskell's ST library yet. It hits this exact use-case, and comes with some pretty sweet safeguards from the type system.

https://wiki.haskell.org/Monad/ST

It allows you mutate arrays and other stuff "on the inside" like this article suggests, but it's also able to wrap up the operation so it appears pure from the outside, so the caller doesn't have to guess or rely on naming conventions to figure out the mutability.

It's your choice on whether you want to do the copy on the way in ('thawing'), on the way out ('freezing'), or both, by using the 'in-place' variants of thaw and freeze.

Re:Copying data is wasteful, mutating data is dangerous by pwm on Thursday January 09, 2020 @08:03PM (#22007585)
Exactly. The only problem is that you need a language with a sufficiently powerful type system that can express both phantom and existential types.
Re:Copying data is wasteful, mutating data is dangerous by chii on Thursday January 09, 2020 @11:34PM (#22008323)
> The only problem is that you need a language with a sufficiently powerful type system

why is that a problem?

Re:Copying data is wasteful, mutating data is dangerous by skosch on Friday January 10, 2020 @10:26AM (#22011585)
Because everyone and their grandma can whip up a quick Python script after a few days of practice, whereas learning Haskell is a much bigger investment?
Re:Copying data is wasteful, mutating data is dangerous by pwm on Friday January 10, 2020 @08:50AM (#22010873)
Problem in the sense that most typed languages don't have a sufficiently powerful/expressive type system.