-- Mark II lazy wheel-sieve. -- Colin Runciman (colin@cs.york.ac.uk); March 1996. -- See article "Lazy wheel sieves and spirals of primes" (to appear, JFP). primes :: [Int] primes = spiral wheels primes squares spiral (Wheel s ms ns:ws) ps qs = foldr turn0 (roll s) ns where roll o = foldr (turn o) (foldr (turn o) (roll (o+s)) ns) ms turn0 n rs = if n0 then n:rs else rs turn o n rs = let n' = o+n in if n'`mod`p>0 then n':rs else rs main = print (primes!!(20000::Int))