[Haskell-cafe] more sharing in generated code
Peter Divianszky
divipp at gmail.com
Sat Nov 3 13:39:07 CET 2012
Hi Dennis,
> I think you mean this:
>
> r { x = f (x r) }
Yes, I made a typo.
Thanks for advising ghc-vis.
> In GHC: In your example a new record is built, but all its entries (x in
> this case) are shared.
The problem is, that in case of nested records, if an inner record is
updated, the whole path to that record is copied.
Of course copying just the path to the inner data is a lot better than
copying the whole tree of data, but my proposal is about to optimize it
further: don't copy of the path if the updated value is identical to the
original one. The Agda compiler may benefit by this optimization for
example.
In fact, the last version of the proposal[^1] will copy the path to keep
laziness properties, but it does it in such a way that the GC can
collect the copied path instead of trying to collect the old path (which
will if it is shared).
[^1]:
http://www.haskell.org/pipermail/haskell-cafe/2012-November/104311.html
Does this make sense to you?
Peter
More information about the Haskell-Cafe
mailing list