I'm asked to remove one clause in below F# function, while maintaining it's functionality, that's alternating between plus and minus.
let rec altsum =
function
| [] -> 0
| [ x ] -> x
| x0 :: x1 :: xr -> x0 - x1 + altsum xr
I stumbled upon below solution, but I don't quite understand how it evaluates to the correct result since it only contain a minus symbol and not a plus symbol. Can someone please explain how below function altsum1 evaluates?
let rec altsum1 =
function
| [] -> 0
| x0 :: xr -> x0 - altsum1 xr