I am using the following function:
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
It works just fine for just about any example i can come up with, but when i call it from other functions in my larger project, for some cases I get an exception:
Exception: projekt.hs:(34,9)-(38,108): Non-exhaustive patterns in function combinations'
Is there something wrong with the above definition? Is it missing some case? I thought otherwise
handles anything that doesn't fall into previous cases.