Hi,

I seem to be landing into infinite recursion when using higher order functions with list comprehension. Take this for an example. The following works well, and gives answers for numbers like 2000000 as well:

primesBelowN :: Integer -> [Integer]
primesBelowN n = 2:3:filter f [6*k+i | k <- [1..(n-1)`div`6], i <- [-1, 1]]
                     where f x = foldr g True xs
                                 where g t ac = (x `rem` t /= 0) && ac
                                       xs = [5, 7..(truncate (sqrt (fromInteger x)))]


However, the following never returns anything for the same number, probably due to some kind of loop malfunction:

primesBelowN :: Integer -> [Integer]
primesBelowN n = 2:3:filter f [6*k+i | k <- [1..(n-1)`div`6], i <- [-1, 1]]
                     where f x = foldr g True xs
                                 where g t ac = (x `rem` t /= 0) && ac
                                       xs = [ m | m <- [5, 7, ..], m <= (truncate (sqrt (fromInteger x)))]

Any ideas what might be going wrong?

Thanks in advance!

DJ