-- 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). module Expr where data Wheel = Wheel Int [Int] [Int] expr :: [Int] expr = primes where 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