Reputation: 49
In the following code Haskell complains about
Non-exhaustive patterns in function prime'
prime :: Int -> [Int]
prime x = prime' [2..x] where
prime' (p:ps)= p : prime' [x | x <- ps, mod x p > 0 && prime'' x [2..div x 2]]
prime'' _ [] = True
prime'' n (x:xs)
| mod n x == 0 = False
| otherwise = prime'' n xs
prime' []=[]
I can't find my mistake. Could someone explain why this happens, and what it means?
Upvotes: 0
Views: 702
Reputation: 105955
Indentation. The last line defines another function called prime'
. Therefore, prime\prime'
(the definition in the where clause of prime
) doesn't have a matching pattern for the empty list.
Also, you're indentation is all over the place. Do you still mix tabs and spaces?
Upvotes: 6