Write a version of sumpairs

Assignment Help JAVA Programming
Reference no: EM13162682

Write a version of sumPairs of Ex. 3.1.8 that sums each component of the pairs separately, returning a pair consisting of the sum of the first components and the sum of the second components. So basically [(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 do 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;

 

 

Unfortunately, it does not work.

 

 

Reference no: EM13162682

Questions Cloud

Write a function that takes a list of integers as argument : Write a function that takes a list of integers as argument and returns a pair consisting of the sum of the even positions and the sum of the odd positions of the list. You should not use any auxiliary functions.
Receiver decide which symbol was originally sent : How can a receiver decide which symbol was originally sent when a received "point" lies somewhere in between other points in the diagram?
Program to translates a number into the closest letter grade : Write a program that translates a number into the closest letter grade. For example, the number 2.8 (which might have been the average of several grades) would be converted to B-. Break ties in favor of the better grade
Program should assign a seat in the first class : If a person enters 1, your program should assign a seat in the first class (rows 1 - 3). If a person enters 2, your program should assign a seat in business class (rows 4 - 7). If a person enters 3, your program should assign a seat in economy class ..
Write a version of sumpairs : Write a version of sumPairs  that sums each component of the pairs separately, returning a pair consisting of the sum of the first components and the sum of the second components. So basically [(3,1)(10,3)] would return (13,4).
The program reads in names : Write a program and include the following methods. The program reads in names and ages (use 2 parallel arrays, maximum size 50) from a file called Stuff.dat.
Design an adt for a two-color : Design an ADT for a two-color, double-stack ADT that consists of two stacks one "red" and one "blue" and has as its operations color-coded versions of the regular stack ADT operations.
How many moles of h2so4 must be present to react completely : How many moles of H2SO4 must be present to react completely with the NaOH delivered from the buret.
What is the actual mass of the uncharged protein : a positive ion ESI mass spectrum of a protein showed a peak at m/z = 1001 resulting from the adition of 10 protons. what is the actual mass of the uncharged protein?

Reviews

Write a Review

JAVA Programming Questions & Answers

  Create four classes

Create four classes: Account.java, Checking.java, Savings.java, and AccountArray.java.

  Create a complete java application

Create a complete Java application that meets these requirements and the program has an opening comments section (using block comments) with the file name, date, your name, and purpose of the program.

  Java class to accept a user-s hourly rate of pay

Write a class that accepts a user's hourly rate of pay and the number of hours worked. Display the user's gross pay, the withholding tax (15% of gross pay), and the net pay (gross pay - withholding).

  Method called wordlengths that accepts a scanner

Write a method called wordLengths that accepts a Scanner representing an input file as its argument. Your method should read from the given file.

  Write java program to reads ten values from user

Write the java program which reads 10 values from user and store them in 1 daimantion array. your program will ask the user wich operation he wants to perform:

  Alter the prototype form page by javascript function

Alter the prototype form page so that when JavaScript function has verified that all the required fields have been filled, cookie is added to user's computer.

  Sorting routine adopted in the java api for arrays.sort()?

What is the sorting routine adopted in the Java API for Arrays.sort()? How different is it from the sorting routine we discussed in class? Is it better? Explain your answers in short clear sentences.

  Develop java package comprising of class using encapsulation

Develop the Java package comprising of Class and Student with the given requirements. Encapsulation, Method to print student details alone.

  Creates an array named odds

Write code that creates an array named odds and stores all odd numbers between -6 and 38 into it using a loop. Make the array's size exactly large enough to store the numbers.

  Determine the visual resolution of resulting image

Drawing in 8.5 by 11 inch sheet is digitized by means of 300 dpi (dots per inch) scanner. Determine the visual resolution of resulting image (number of dots in each dimension)?

  Write java program to evaluate postfix expressions

Write a java program to evaluate postfix expressions containing complex numbers using a stack. This program should contain two classes.

  Write a java application to ask number of assignments

Write a java application that accomplishes the following tasks with built in exception handling: ask the number of homework assignment students have submitted in a semester

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd