Question: 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:

```hs
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

```hs
countIncreases [1,2] 0

```

I paste all this code in `ghci` but get the error

```hs
Non-exhaustive patterns in function countIncreases

```

I think however that all patterns needed for that case are matched:

1. 1st iter.: `x = 1`, `y = 2`, `r = []` and `c = 0`. `2 > 1` so we get in the 1st branch and call `countIncreases (2:[]) (0 + 1)`
2. 2nd iter.: `c = 1` so return `1`

What am I doing wrong?

Answer: 
You forgot to consider the empty list (`[]`) case:

```
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
countIncreases [] c = c  -- here! 

```

If you think the function should never be called like that, however, you can throw an error:

```
countIncreases [] _ = error "countIncrease on empty list!" 

```

---

On the other hand, I can't reproduce the error on your test.
Thank you guys for answering my question. Turns out the root of the problem was something different. Key thing is the fact that I was using `ghci` and inserting the overloads line by line thinking each line adds an overload to the function definition. Turns out with each line I was overwriting the previous input. So there was always only the last one present in the memory.

From [this question](https://stackoverflow.com/questions/2846050/how-to-define-a-function-in-ghci-across-multiple-lines) I learned how to do multiline input in `ghci` and following that my function works fine.