Hi Akash,
Thanks for the response. A very simple and lucid explanation. Looks interesting.
So, here's the big picture now, for which I need this. I intend to implement a lookalike Sieve of Eratosthenes algorithm in haskell. For this, I intend to use the earlier function recursively, as follows:
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 <- primesBelowN n, m <= (truncate (sqrt (fromInteger x)))]
Of course, I could do something like this:
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 <- primesBelowN (truncate (sqrt (fromInteger x)))]
However, this calls primesBelowN function with a new argument everytime. I suppose that is not optimal (correct me if I am wrong).
Point number 2: both fail. Grrh.
Any ideas how I could go recursive with this function?
Dushyant