[Haskell-cafe] Expanding do notation
David F. Place
d at VIDPLACE.COM
Sat Jan 7 11:23:35 EST 2006
Hi All,
Is there a program for expanding 'do' notation? I am trying to
understand why the following code (from the Fannkuch entry) doesn't
hold onto the list 'p' causing a space leak.
main = do n <- getArgs >>= return . read . head
let p = permutations [1..n]
mapM_ (putStrLn . concatMap show) $ take 30 p
putStr $ "Pfannkuchen(" ++ show n ++ ") = "
putStrLn . show $ foldl' (flip (max . steps 0)) 0 p
If I add a line which refers to 'p' at the end, there is a space leak.
print (head p)
Thanks.
Cheers, David
---------without extra line
./Latest 9 +RTS -K256m -c -sstderr
123456789
...
Pfannkuchen(9) = 30
244,215,012 bytes allocated in the heap
613,972 bytes copied during GC
3,920 bytes maximum residency (1 sample(s))
931 collections in generation 0 ( 0.06s)
1 collections in generation 1 ( 0.00s)
1 Mb total memory in use
INIT time 0.00s ( 0.01s elapsed)
MUT time 2.20s ( 2.72s elapsed)
GC time 0.06s ( 0.13s elapsed)
EXIT time 0.00s ( 0.00s elapsed)
Total time 2.26s ( 2.86s elapsed)
%GC time 2.7% (4.5% elapsed)
Alloc rate 111,006,823 bytes per MUT second
Productivity 97.3% of total user, 76.9% of total elapsed
--------with extra line
./Latest 9 +RTS -K256m -c -sstderr
...
Pfannkuchen(9) = 30
[1,2,3,4,5,6,7,8,9]
244,216,248 bytes allocated in the heap
19,804,816 bytes copied during GC
10,586,416 bytes maximum residency (6 sample(s))
931 collections in generation 0 ( 0.96s)
6 collections in generation 1 ( 1.28s)
18 Mb total memory in use
INIT time 0.00s ( 0.01s elapsed)
MUT time 2.30s ( 2.72s elapsed)
GC time 2.24s ( 3.15s elapsed)
EXIT time 0.00s ( 0.00s elapsed)
Total time 4.54s ( 5.88s elapsed)
%GC time 49.3% (53.6% elapsed)
Alloc rate 106,180,977 bytes per MUT second
Productivity 50.7% of total user, 39.1% of total elapsed
--------------------------------
David F. Place
mailto:d at vidplace.com
More information about the Haskell-Cafe
mailing list