
Max Bolingbroke wrote:
Heinrich Apfelmus wrote:
As I understand it, GHC implements the technique from Sparud's paper, so this is a solved problem.
This is not my understanding. As far as I know, the STG machine has a special notion of "selector thunks", which represent projections from product data types. These selector thunks are evaluated by the GHC garbage collector in the manner proposed by Wadler.
Ah, that's how it is. Thanks. :) Funny that this special garbage collector support isn't used when compiling with -O0, though. But it makes sense to be required to use at least -O1 when you care about resources.
The Sparud solution is IMHO much cleaner, though!
I agree. It still requires special support from the garbage collector, though. Namely, the gc has to short-circuit indirection nodes, otherwise the pairs will be replaced by a long chain of indirection nodes and the break example would still leak. In a sense, Sparud's idea is about expressing selector thunks in terms of indirections and mutable thunk updates. Regards, Heinrich Apfelmus -- http://apfelmus.nfshost.com