[Haskell-cafe] laziness

Ranjan Bagchi ranjan.bagchi at frotz.com
Sun Dec 10 00:31:11 EST 2006

Hi --

I'm using ghc 6.6, and I had some questions about the extend of  
laziness and foldr.

I've noticed the following:
 >x = foldr (:) [] [1..]
 >(take 10) x

yields [1..10]

Which is great.. however, what I'd like to fold the list over a tuple:
 >foo x (l,payload) = ((x:l), payload)
 >(x,_) = foldr foo ([], Nothing) [1..]
 >(take 10) x

Doesn't terminate, until the stack overflows

So I'm clearly expecting ghc to be more psychic than it's currently  
capable.  But what I'd like to do is pass an infinite list through a  
processing function which maintains some state (foo could easily be a  
pseudo random number generator), and take the first bit of it.

Any help?


Ranjan Bagchi

More information about the Haskell-Cafe mailing list