在Haskell中解决递归问题后出现警告



我正试图实现下面的代码问题,但我得到了这种类型的警告。我不知道发生了什么,因为我可以正确输出答案。下面是我的代码和警告:

continuous :: [Integer] -> Bool
continuous list = case list of 
[] -> True
[x,y] 
| abs (x-y) <= 1 -> True 
| otherwise -> False
x:y:xs 
| abs(x-y) <= 1 -> continuous (y:xs)
| otherwise -> False 
Lists.hs:43:19: warning: [-Wincomplete-patterns]
Pattern match(es) are non-exhaustive
In a case alternative: Patterns not matched: [_]
|
43 | continuous list = case list of 
|                   ^^^^^^^^^^^^^...

警告注意,您的模式匹配不是详尽的,因为您错过了具有单个元素的列表的情况,例如[x]

此外,如果您为单个元素添加一个case,则不再需要case[x,y],因为它也由casex:y:xs处理,因为xs也可以表示空列表

最新更新