<br><br><div><span class="gmail_quote">On 1/7/06, <b class="gmail_sendername">Chris Kuklewicz</b> <<a href="mailto:email@example.com">firstname.lastname@example.org</a>> wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
When you put "print (head p)" at then end, it keeps a reference to the<br>whole list "p" which is your space leak. If you want to store the head<br>of p, this *should* work:<br><br>> main = do n <- getArgs >>= return . read . head
<br>> let p = permutations [1..n]<br>> headOfP <- return (head p)<br>> mapM_ (putStrLn . concatMap show) $ take 30 p<br>> putStr $ "Pfannkuchen(" ++ show n ++ ") = "
<br>> putStrLn . show $ foldl' (flip (max . steps 0)) 0 p<br>> print headOfP<br><br>The "headOfP" is computed as an IO action at that point in the program,<br>so "headOfP" does not hold a reference to "p" as a whole.
</blockquote><div><br>Without having tried this I'd say that you should use Control.Excection.evaluate instead of 'return'. Or you could use 'seq'. I suspect that otherwise the 'head p' will not be evaluated until the last line and you will have the same problem as before.