I am trying to write a basic recursive function that calculates the alternating sum of a list of numbers ([1, 2, 3] -> 1 - 2 + 3). I am fairly new to Haskell, so I have just been toying around with this problem with little success. Below is my most recent attempt. It works with lists of up to length two.
alternateSum [] = 0
alternateSum (p:ps) = if odd (length ps) then
p - alternateSum ps
else
p + alternateSum ps