Trying to create a Haskell program that increments every number in a list by one.
module Add1List where
add1_list_comp :: [Integer] -> [Integer]
add1_list_comp [x] = [x + 1| x <- [x]]
It works when I call this add1_list_comp [3] … it gives me [4]
But when I do add1_list_comp [3, 4, 5] … it throws me an error saying
“non-exhaustive patterns in function add1_list_comp”
Any help would be much appreciated!
that simple
or, in your way
the problem with your code is that
does pattern match on list with single item, that’s why it fails on list with several items.