【发布时间】:2015-05-16 15:24:56
【问题描述】:
在 idris 0.9.17.1 中,
灵感来自https://wiki.haskell.org/Prime_numbers, 我编写了以下代码来生成素数
module Main
concat: List a -> Stream a -> Stream a
concat [] ys = ys
concat (x :: xs) ys = x :: (concat xs ys)
generate: (Num a, Ord a) => (start:a) -> (step:a) -> (max:a) -> List a
generate start step max = if (start < max) then start :: generate (start + step) step max else []
mutual
sieve: Nat -> Stream Int -> Int -> Stream Int
sieve k (p::ps) x = concat (start) (sieve (k + 1) ps (p * p)) where
fs: List Int
fs = take k (tail primes)
start: List Int
start = [n | n <- (generate (x + 2) 2 (p * p - 2)), (all (\i => (n `mod` i) /= 0) fs)]
primes: Stream Int
primes = 2 :: 3 :: sieve 0 (tail primes) 3
main:IO()
main = do
printLn $ take 10 primes
在 REPL 中,如果我写 take 10 primes,REPL 会正确显示 [2, 3, 5, 11, 13, 17, 19, 29, 31, 37] : List Int
但是如果我尝试:exec,什么都不会发生,如果我尝试编译并执行程序,我会得到Segmentation fault: 11
谁能帮我调试一下这个问题?
【问题讨论】:
-
您应该在 GitHub 上提交错误报告。显然存在编译器错误。
标签: idris