所以,我是一个办法懒洋洋地生成素数的工作,我想出了这三个定义,这在同等方式,所有的工作 - 只是检查每个新的整数是否具有上述所有质数中的一个因素:
primes1 :: [Integer]
primes1 = mkPrimes id [2..]
where mkPrimes f (x:xs) =
if f (const True) x
then
let g h y = y `mod` x > 0 && h y in
x : mkPrimes (f . g) xs
else
mkPrimes f xs
primes2 :: [Integer]
primes2 = mkPrimes id (const True) [2..]
where mkPrimes f f_ (x:xs) =
if f_ x
then
let g h y = y `mod` x > 0 && h y …Run Code Online (Sandbox Code Playgroud)