[Haskell-beginners] Seq question

Lee Short blackcat at pro-ns.net
Tue Apr 17 22:56:44 CEST 2012

I've got the following code, and I'm not sure why the seq seems to be 
doing nothing.  The code should never terminate if the seq were forcing 
the full evaluation of y.  Instead, it runs just fine (though stack 
overflows if I ask for too many elements of primes).  I didn't see 
anything in the tutorial section of haskell.org that seems to explain 
this -- pointers to a useful source would be welcome.

sieve :: [Int] -> [Int]
sieve xs =
    let ys = filter (\z -> 0 /= z `mod` head xs) xs
    in seq ys $ head xs:sieve ys

primes = sieve [2..]


More information about the Beginners mailing list