I'm writing a function that takes an input a list, creates sublists, and retrieves n elements that it outputs into a new list. I'm writing guards depending on the value of the inputs, but I keep getting the error "Patterns not matched: (:) _".
Anyone identifies the issue?
nKsets :: [Int] -> Int -> [[Int]]
nKsets [] _ = error "Empty list should not be given as input"
nKsets l n
| n <= 0 = []
| n > 0 = ...
The error I'm getting is:
Pattern match(es) are non-exhaustive
In an equation for ‘nKsets’: Patterns not matched: (_:_) _
The exhaustivity matcher doesn't know that all values of
nare either greater than 0 or not greater than 0, so it assumes that your second definition is not exhaustive. Useotherwiseinstead ofn > 0to guarantee that a guard succeeds.You can also use a third definition instead of two guards on the second: