The problem is:
“Run-length encoding of a list. Use the result of problem P09 to implement the so-called run-length encoding data compression method. Consecutive duplicates of elements are encoded as lists (N E) where N is the number of duplicates of the element E.”
The expected result is:
λ> encode "aaaabccaadeeee"
[(4,'a'),(1,'b'),(2,'c'),(2,'a'),(1,'d'),(4,'e')]
I've created this code:
encode [] = []
encode (x:xs) = (counting xs,x) : encode (dropWhile (==x) xs )
where counting (y:ys)
| y == head ys = 1 + counting ys
| otherwise = 0
The repl is saying:
`<interactive>:(1,1)-(5,22): Non-exhaustive patterns in function encode`
I can't figure out where is my recursion mistake.
I solved this way. Conta is the couting function.