Mar*_*cin 1 combinations haskell non-exhaustive-patterns
我使用以下功能:
combinations :: Int -> [a] -> [[a]]
combinations k xs = combinations' (length xs) k xs
where combinations' n k' l@(y:ys)
| k' == 0 = [[]]
| k' >= n = [l]
| null l = []
| otherwise = Prelude.map (y :) (combinations' (n - 1) (k' - 1) ys) ++ combinations' (n - 1) k' ys
Run Code Online (Sandbox Code Playgroud)
它适用于我可以提出的任何示例,但是当我从我的大项目中的其他函数调用它时,在某些情况下我得到一个例外:
Exception: projekt.hs:(34,9)-(38,108): Non-exhaustive patterns in function combinations'
Run Code Online (Sandbox Code Playgroud)
上面的定义有问题吗?是否遗漏了一些案例?我认为otherwise处理任何不属于以前情况的东西.