
my line of work). This got me thinking about one of the largest problems with writing serious numerical code in Haskell, which is that of memory consumption and avoiding temporary variables. ... pretty high-level pure functional code, while the RTS can realize at run-time that we have the only reference to the input argument and that it is therefore safe to consume it destructively. My thought is to move some of the amazing rewriting streams stuff that's going on with Data.ByteStream and Manuel's array fusion work onto the memory management level. If we can rewrite high-level array manipulations into a form in which the compiler can fuse the loops and write good low-level code, why not also allow automatic in-place updates (when possible)?
fusing loops over arrays already avoids temporaries, doesn't it? one thing that struck me when reading the rewriting strings paper was that it reduces structure fusion to loop-over-structure fusion which would finally provide a framework for borrowing all that nice work on with-loop-folding in SAC for Haskell arrays (all of those high-level array operations in SAC seem to be reducable to with-loops). Single Assignment C -- Efficient Support for High-level Array Operations in a Functional Setting. Sven-Bodo Scholz. In Journal of Functional Programming 13(6), pp.1005-1059, ©Cambridge University Press, 2003. http://www.sac-home.org/publications/sac-overview-jfp-03.pdf [section 4.2 in the papger is on with-loop folding] SAC home page, about SAC http://www.sac-home.org/index.php?p=.%2F11_About%2F11_About_SAC anyone for porting the array sublanguage (shape- and dimension-invariant operations on multi-dimensional arrays) of SAC to Haskell? how much of that is covered in the ongoing Haskell array work?
The key is that copy will ask the GC to check whether there is more than one reference to its input, and if there isn't, then it'll return its input without making a copy.
Obviously, we'd want to be careful in making calls to copy (since the GC overhead could overwhelm the potential (transient) memory savings.
SAC uses reference counting for that. as for using forced GC to get similar effects, i'm not optimistic, as that would seem to invalidate the advantages of GC-based memory management. btw, the nice thing about making a copy is that you know you now have the only reference to that copy. so you could make a copy, then update in place to your heart's content, until you pass on your reference to others. claus