Rai*_*ain 0 recursion haskell list
我正在尝试实现下面的代码问题,但我收到了此类警告。我不知道发生了什么,因为我可以正确输出答案。下面是我的代码和警告:
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
| ^^^^^^^^^^^^^...
Run Code Online (Sandbox Code Playgroud)
小智 5
[x]该警告指出,您的模式匹配并不详尽,因为您缺少例如具有单个元素的列表的情况。
此外,如果为单个元素添加 case ,则[x,y]不再需要 case ,因为它也由 case 处理x:y:xs,因为xs也可以表示空列表