I've defined the infinite list of infinite lists pathCounts
and the infinite list of finite lists pathCounts'
:
import Data.Function (fix)
nextRow xs = fix $ \ys -> zipWith (+) xs (0:ys)
pathCounts = repeat 1 : map nextRow pathCounts
pathCounts' = map (take 100) pathCounts
Dropping into ghci, if I haven't evaluated either at all, I can use :p
on either successfully:
ghci> :p pathCounts
pathCounts = (_t1::[[Integer]])
ghci> :p pathCounts'
pathCounts' = (_t2::[[Integer]])
But if I evaluate pathCounts'
partially, then :p
freezes on pathCounts
while still succeeding on pathCounts'
:
ghci> head . head $ pathCounts'
1
ghci> :p pathCounts'
pathCounts' = (1 : (_t4::[Integer])) : (_t5::[[Integer]])
ghci> :p pathCounts
^CInterrupted.
I'd expect :p pathCounts
to print the same as :p pathCounts'
, as I've only partially evaluated it. Why isn't it working?
:p pathCounts
that last time. Examine your RAM usage in your system monitor when you call it, mine jumped up to full usage pretty quickly. My guess would be that for whatever reason the partial evaluation ofpathCounts'
then makes:p pathCounts
try to evaluate therepeat 1
term ofpathCounts
. What happens if you tryhead . head . tail $ pathCounts'
? I would assume you get a space leak again. – UnterwaldenpathCounts'
is a bit of a distraction - I was just trying to demonstrate that:p
worked for a partially evaluated infinite list of finite lists. The leak happens if I inspect any part ofpathCounts
, directly or indirectly. – Marybelleghci> let pcs = repeat $ repeat 1 :: [Int]
,ghci> pcs !! 0 !! 0
,ghci> :p pcs
– Marybelle