Help: Stack-overflow and tail-recursive functions
oleg@pobox.com
oleg@pobox.com
Thu, 19 Jun 2003 19:19:35 -0700 (PDT)
It seems the problem is indeed in rmat:
> rmat n = listArray ((1,1),(n,n)) $ map ct (randoms (mkStdGen 1) ::[Bool])
> where ct True = Unknown
> ct False = Dead
To be more precise, the problem is in randoms. If you replace rmat
with the following
rmat n = array ((1,1),(n,n)) $
zipWith (\ind v -> v `seq` (ind,v)) [(i,j) | i<-range, j<-range] $
map ct (randoms (mkStdGen 1) ::[Bool])
where ct True = Unknown
ct False = Dead
range = [1..n]
then
> main = putStrLn $ show $ forpaintbdry $ rmat 400
computes without problems (compiled with GHC 5.04.1, no flags). BTW,
GHCi didn't have any problem even with the original code.