Stack size

Alastair David Reid reid@cs.utah.edu
13 Sep 2001 12:47:12 -0600


> I'm using the Feb 2000 release of Hugs and am preparing student labs
> using the graphics library.  Several nasties happen:

> * For very moderate problems (plot ~2K lines centred in a window of
> fixed size) I get a control stack overflow.  To centre, the code
> finds pre-computes the minimum and maximum x and y ordinates of all
> line end-points.  This is potentially a problem, but fixable in this
> case, you'd hope.  However, the overflow happens EVEN IF the code is
> written tail-recursive, or using foldl.  Oh dear.

This could well be a strictness problem.

foldl often has little effect on strictness problems.
What you need is foldl' which forces (using $!) the 
accumulator parameter on each iteration.

foldl' is defined and used in Hugs' Prelude but is not exported
because it is not sanctioned by the Haskell standard.
  
  foldl'           :: (a -> b -> a) -> a -> [b] -> a
  foldl' f a []     = a
  foldl' f a (x:xs) = (foldl' f $! f a x) xs
  

As for why Hugs and the HGL are able to corrupt the entire screen on
Win2000, I can only say that I am very impressed by MS's ability to
put so much functionality into their system and have it ever work. :-)

-- 
Alastair Reid        reid@cs.utah.edu        http://www.cs.utah.edu/~reid/