News for hackers. Stuff that matters.
Re:Measuring GC latencies in Haskell, OCaml, Racket by OskarS on Monday December 05, 2016 @10:26AM (#13105899)
I have a really dumb question about the Haskell GC, which I've never been brave enough to ask, but here goes:

I thought everything in Haskell was immutable? If so, wouldn't that imply that it's impossible to create cyclic references (i.e. A and B can't both reference each other, because one of them has to be created first, and once created, it's immutable)?

Couldn't you then just use reference counting to decide when to recycle objects instead of having full-blown GC pauses? Or is it too expensive to keep a reference count on all those objects and keep it updated? Whatever cost it has, it seems much more preferable to me compared to 50 ms GC pauses for relatively simple code.

Re:Measuring GC latencies in Haskell, OCaml, Racket by openasocket on Monday December 05, 2016 @10:44AM (#13106104)
Not a dumb question at all! You can create cycles in Haskell thanks to lazy evaluation. I can make a circular list in Haskell with the following:

x :: [Int]

x = 0 : y

y :: [Int]

y = 1 : x

And thus we have a circular list with the elements 0 and 1. It's technically an infinite-length list with 0 and 1 repeating forever, but Haskell will represent this in memory as a circular list.

Re:Measuring GC latencies in Haskell, OCaml, Racket by OskarS on Monday December 05, 2016 @11:38AM (#13106633)
Ah, I see, I figured that there might be some case like that. I would have expected that to be a compile-time error because `y` is an unrecognized identifier by the time `x` is defined, but I guess it makes sense with lazy evaluation to not make that kind of ordering matter.
Re:Measuring GC latencies in Haskell, OCaml, Racket by tener on Monday December 05, 2016 @03:14PM (#13108987)
Lazy evaluation is not important item here. It is merely the semantics is defined in a way that the order of declarations does not matter.

Other languages have this property too - say, C# (not entirely true, but pretty close - at least if you think about top level methods etc.).

Also an example where the order of declarations does not matter at all, because there is just one declaration:

   x :: [Integer]
   x = 0 : 1 : x
Re:Measuring GC latencies in Haskell, OCaml, Racket by hood_syntax on Monday December 05, 2016 @02:11PM (#13108301)
Yeah, all definitions are module level unless they are scoped in let or where blocks (someone correct me if I'm mistaken)
Re:Measuring GC latencies in Haskell, OCaml, Racket by tel on Monday December 05, 2016 @10:53AM (#13106189)
It ought to, yes. More specifically, immutability means that you cannot observe sharing. What this means is that it's easy to break sharing and if you rely on it for performance you might face difficulties.

But you can create it. Names are shared:

    let x = [1, 2, 3] in [x, x, x]
There are more exotic ways, too.
Re:Measuring GC latencies in Haskell, OCaml, Racket by dllthomas on Tuesday December 06, 2016 @11:23AM (#13115793)
The key thing missing from the responses so far is that laziness is a (particularly constrained) kind of mutability.
Re:Measuring GC latencies in Haskell, OCaml, Racket by Ono-Sendai on Monday December 05, 2016 @01:08PM (#13107638)
Yes you are correct, for statically typed (and not lazy) functional languages. In this case Ref counting will work fine since you can't create cycles. See http://www.forwardscattering.org/post/47
Re:Measuring GC latencies in Haskell, OCaml, Racket by cordite on Monday December 05, 2016 @10:32AM (#13105981)
Usually copying is only to compact everything alive back together for cache friendliness. However, it shouldn't need a stop the world for that due to immutability.