3 Feb 2009 16:26
Re: Circular Linked Lists
Dave Bayer <bayer <at> cpw.math.columbia.edu>
2009-02-03 15:26:12 GMT
2009-02-03 15:26:12 GMT
On Feb 3, 2009, at 10:15 AM, Dave Bayer wrote: > > The following takes forever, but it doesn't consume memory: > >> Prelude> :m Data.List >> Prelude Data.List> genericIndex (zip (cycle [1..3]) (cycle [1..4])) >> (1000^1000) > > So zip is doing something smart here with cyclic lists. No, I just wasn't saving the head. This burns memory: > Prelude Data.List> let a = zip (cycle [1..3]) (cycle [1..4]) > Prelude Data.List> head a > (1,1) > Prelude Data.List> genericIndex a (1000^1000) > <interactive>: memory allocation failed (requested 2097152 bytes)
RSS Feed