Compact Regions with Lazy Evaluation
Currently, adding a value to a compact region evaluates it to normal form. I'm wondering if it's possible to have another compacting primitive that can add unevaluated thunks to a compact region. These thunks would be evaluated as they were demanded, and the resulting values would be added to the compact region. I actually have a use case for this in mind involving very large map-like data structures whose size exceeds system memory when in normal form but that are largely unevaluated, giving them a memory footprint that is a fraction of what it would be.
One problem would be that a compaction failure (from someone trying to stick a function or a
MutableArray# into a compact region) would happen after the call to
compactLazy, so you end up with all the usual lazy IO problems. Another problem would be that the thunks wouldn't get GCed, since they would live in a compact region (and also because you could not update the references to the thunk, since compact regions are not scanned during GC). Neither of these are absolute deal-breakers though.
Are there other problems that make this fundamentally impossible to do? Or is this something that could conceivably be added?