Space usage

Malcolm Wallace Malcolm.Wallace at
Tue Aug 17 12:11:32 EDT 2004

"Simon Peyton-Jones" <simonpj at> writes:

> I had a look at this.  It's an old chestnut: lazy pattern matching.  You
> have
> 	let ((commands, s), x) = run (read iters) 5
> 	in do something with commands...
> 		print x
> Trouble is, the 'x' hangs onto both components of the pair, even though
> it only needs one.
> This lazy-pattern-matching leak is a well-known problem, to which I do
> not know a good solution.  There was a paper from Chalmers about 8 years
> ago about building more cleverness into the compiler, but it amounted to
> extending Core with a lazy tuple binding.  Fair enough, but quite a big
> addition to Core and one I've never done.

You probably mean
    J. Sparud, "Fixing Some Space Leaks without a Garbage Collector", FPCA'93.

as implemented in hbc.  It is also possible to use Wadler's
garbage-collector fix for this space leak, as implemented in nhc98.
    P Wadler, "Fixing a Space Leak with a Garbage Collector", SP&E Sept 1987.

When the GC discovers a selector function applied to an evaluated
argument, it "evaluates" the selector on-the-fly by just swizzling
pointers.  It needs some co-operation from the compiler to make
selector functions look obvious, but that isn't too difficult.


More information about the Glasgow-haskell-users mailing list