Write a version of sumpairs of ex 318 that sums each


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.

Request for Solution File

Ask an Expert for Answer!!
Computer Engineering: Write a version of sumpairs of ex 318 that sums each
Reference No:- TGS0962068

Expected delivery within 24 Hours