I am doing a programming exercise in Haskell, in which I give some values in a list, for example [1, 2, 2, 3, 4] and it should be as follows [1, 4, 3, 4]. So far the program works without problems for me with the following code:
sustituirSumando [x,y]
| x==y = [x+y]
| otherwise = [x,y]
sustituirSumando [x,y,z]
| x==y = [x+y,z]
| y==z = [x,y+z]
|otherwise = [x,y,z]
sustituirSumando (x:y:xs)
| x==y = (x+y) : sustituirSumando (xs)
| otherwise = x: sustituirSumando (y:xs)
Where I don't know how to proceed is in the following supposed example [1, 2, 2, 4, 5] here the list should be as follows [1, 8, 5] but in my code it remains [1, 4, 4, 5]. Thanks in advance.