I wanted to use this code of Sieve of Eratosthenes from this page: http://ift.tt/1PZk80r def:primes_naive
Only a bit modified, so it only shows the primes up to a number:
primes :: Integral a => a -> [a]
primes m = sieve [2..m]
where
sieve (p:xs) = p : sieve [x|x <- xs, x `mod` p > 0]
But in WinGHCi always the error comes (example 10):
primes 10
[2,3,5,7*Main> *** Exception: eratosthenes.hs:4:5-55: Non-exhaustive patterns in function sieve
I know this error from recursive functions, where for example cases are missing, but what is missing here?
Aucun commentaire:
Enregistrer un commentaire