Rai*_*low 2 recursion primes haskell pattern-matching non-exhaustive-patterns
我想从这个页面使用Sieve of Eratosthenes的代码:http://en.literateprograms.org/Sieve_of_Eratosthenes_(Hackaskell)#chunk def:primes_naive
只有一点修改,所以它只显示一个数字的素数:
primes :: Integral a => a -> [a]
primes m = sieve [2..m]
where
sieve (p:xs) = p : sieve [x|x <- xs, x `mod` p > 0]
Run Code Online (Sandbox Code Playgroud)
但是在WinGHCi中总是出现错误(例10):
primes 10
[2,3,5,7*Main> *** Exception: eratosthenes.hs:4:5-55: Non-exhaustive patterns in function sieve
Run Code Online (Sandbox Code Playgroud)
我从递归函数中知道这个错误,例如缺少案例,但这里缺少什么?