3 ms·
Thoughts on Immutability in D
- nickpp 15y agoYeah, I really miss the mutable pattern for lazy instantiation too..
- Peaker 15y agoThat's at least one good reason for Haskell to have built-in laziness. The implementation of laziness uses side-effects. The interface it exposes is pure/immutable. If you had to implement it yourself, out of effectful primitives, the result would have an effectful type, despite being pure. So it is simply exposed as a pure primitive, despite being implemented via effects under the hood. Pretty much all of the pure operations (e.g: add) boil down to impure/effectful operations deep down (e.g: an ADD instruction mutating a register). That's why it is important to have an escape hatch -- capable of saying: "This is a composition of effects, but I know it is pure". In Haskell, this is called unsafePerformIO, and it has the (impossible) type: unsafePerformIO :: IO a -> a If you use this on a non-pure composition of effects, you get a bug.
- Poita_ 15y agoThe implementation of everything uses side-effects :-) A computer is nothing more than a state machine after all. You are right though. It's nice to have escape hatches. D allows this through cast, but unfortunately casting away const causes undefined behaviour.