I just started learning Haskell and have a problem writing a basic function.
This function should tell me for how many elements of an array the previous element is bigger than the current one. Here's the code:
countIncreases :: (Ord a, Num b) => [a] -> b -> b
countIncreases [x] c = c
countIncreases (x:y:r) c
| y > x = countIncreases (y:r) (c+1)
| otherwise = countIncreases (y:r) c
I try to test it with
countIncreases [1,2] 0
I paste all this code in ghci but get the error
Non-exhaustive patterns in function countIncreases
I think however that all patterns needed for that case are matched:
- 1st iter.:
x = 1,y = 2,r = []andc = 0.2 > 1so we get in the 1st branch and callcountIncreases (2:[]) (0 + 1) - 2nd iter.:
c = 1so return1
What am I doing wrong?