Why do I get “non-exhaustive patterns in function”?

回眸只為那壹抹淺笑 提交于 2020-01-17 02:21:09

问题


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?


回答1:


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?



来源:https://stackoverflow.com/questions/24941169/why-do-i-get-non-exhaustive-patterns-in-function

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!