在方法上获取非详尽模式异常



我不断收到以下方法non-exhaustive pattern异常:

 groups::[Int]->[[Int]]
 groups ls=go ls [] [] where
        go [] small big=small:big
        go (x:xs) (y:ys) big | x==y = go xs (x:y:ys) big
                             | otherwise = go xs [] ((y:ys):big)
我想

做的是:给定一个数组[1,2,3,3,4,4,4,1]我想将其拆分为连续重复项列表:[[1],[2],[3,3],[4,4,4],[1]] .

我正在使用 2累加器 ,一个用于当前形成列表,另一个用于大列表。

我不能将wild-card用于big列表,也不能用于small列表,因为唯一不寻常的情况是空输入列表。

你还没有考虑过类似 go (x:xs) [] big 的东西; 唯一允许第二个参数为空列表的情况也要求第一个参数也是空列表。

    go [] small big=small:big
    go (x:xs) (y:ys) big | x==y = go xs (x:y:ys) big
                         | otherwise = go xs [] ((y:ys):big)
    go (x:xs) [] big = ???

最新更新