I need to make a function primes which is not taking any parameter and returns me the list of all the prime numbers. This is the code I came up with:
isqrt = floor . sqrt . fromIntegral
primes = 2:3:(primes' 4)
primes' n =
if (all(\y-> (y < isqrt n) && ((n `mod` y) /= 0)) primes)
then
n:primes' (n+1)
else
primes` (n+1)
The program prints only 2:3: and then it stops. Shouldn't this work because of the lazy evaluation? (by taking primes as the list constructed until now and be able to see if my current number is divisible by any of the numbers in that list and then if yes append it and continue the recursion, if not keep going).
Can anyone please point me towards my mistake?