4 ms·
I didn't downvote you, but you are mistaken. I don't know about Go GC but your comment about Haskell is very off. > Not sure how Haskell's GC works, but I'm g
by kccqzy 7y ago
I didn't downvote you, but you are mistaken.
I don't know about Go GC but your comment about Haskell is very off.
> Not sure how Haskell's GC works, but I'm guessing it more or less depends on Haskell's immutability guarantees.
This is false. Just because you see immutability on the surface doesn't mean the GC still sees a lot of immutability.
Several reasons. The first is that even pure code can depend on interior mutability in a safe way using the ST monad, or in an unsafe way using the IO monad. (The GC can't just say, I give up when a user uses an unsafe function.) You might think that interior mutability is rarely used, but that'd still be wrong. Even something as commonplace as a hash map (from unordered-containers) uses interior mutability under the hood. Just read the source code and you'll see it. Here: http://hackage.haskell.org/package/unordered-containers-0.2.10.0/docs/src/Data.HashMap.Base.html http://hackage.haskell.org/package/unordered-containers-0.2.... Just grep for runST.
The bigger problem is laziness. How is laziness implemented? A value is represented as an unevaluated thunk, a closure to compute the value. When the value is needed, the closure is run and then replaced by the resulting data. This is mutability. And this is something that almost every Haskell program relies on.
I've explained this many times on HN. See eg https://news.ycombinator.com/item?id=21674749 https://news.ycombinator.com/item?id=21674749
- __s 7y agoIt isn't entirely false. Haskell's GC can take some shortcuts when dealing with immutable objects as they can't reference objects older than themselves, including referencing themselves
- hope-striker 7y agoReally? I have no experience with Haskell's internals, but self-referential objects are fairly common in Haskell thanks to its non-strictness. The simplest one is probably the list with one element repeated forever. ones = 1:ones
- kccqzy 7y agoIf objects can't reference themselves, do you think recursion is impossible in Haskell? powersOf2 = 0 : scanl (+) 1 (tail powersOf2) fibonacci = 0 : scanl (+) 1 fibonacci As I have already explained, immutable objects in Haskell often use laziness. And laziness requires mutability.
- __s 7y agoI'm an idiot. I meant that objects can't reference objects newer than themselves
- throwaway894345 7y agoAh, thanks for correcting me. Like I said, I am unfamiliar.
- hope-striker 7y ago> The bigger problem is laziness. How is laziness implemented? A value is represented as an unevaluated thunk, a closure to compute the value. When the value is needed, the closure is run and then replaced by the resulting data. This is mutability. And this is something that almost every Haskell program relies on. Tangent: does GHC ever decide that it's cheaper to just potentially evaluate something twice than to use thunks?