Question: Write a version of sumPairs of Ex. 3.1.8 that sums each component of the pairs discretely, returning a pair consisting of the sum of the first components and the sum of the second components. So essentially [(3,1)(10,3)] would return (13,4).
Ex. 3.1.8
fun sumPairs(nil) = 0
| sumPairs((x,y)::zs) = x + y + sumPairs(zs);
I'm trying to solve this by using the let, in, and end. Here is what I have so far:
fun sumPairs(nil) = 0
| sumPairs((x,y)::zs) =
let
val P = x + sumPairs(zs);
val Q = y + sumPairs(zs)
in
sumPairs(P,Q)
end;
Unluckily, it does not work.
I wrote this but it's not working. Can you please help me edit the code so it works or else prepare a new code.