相关疑难解决方法(0)

Haskell风格/效率

所以,我是一个办法懒洋洋地生成素数的工作,我想出了这三个定义,这在同等方式,所有的工作 - 只是检查每个新的整数是否具有上述所有质数中的一个因素:

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)

performance primes haskell lazy-evaluation

6
推荐指数
1
解决办法
1292
查看次数

标签 统计

haskell ×1

lazy-evaluation ×1

performance ×1

primes ×1