Homework 3
1 IntroductionFor this homework, you will implement some SML functions using list and tupledata structures.1. You may reuse any functions you have already de ned for a previousquestion.2. Your solution should be a working ML program in a text le that I canrun on a console using command like use hwk3.sml;3. You may add comments to your program such as (* Question 1 *).4. Some of these functions involve recursion.2 Questions1. Write a function plus that adds two complex numbers, where a complexnumber is written as a tuple of two integers. For example, (1; 2) is acomplex number with real part 1 and imaginary part 2.plus ((1, 2), (3, 4)) should return (4, 6).2. Write a function times that multiples two complex numbers. For example,times ((1,2), (3,4)) should return (1 * 3 2 * 4, 1 * 4 + 2 * 3),which is (~5, 10,).3. Write a function until that takes two integers x and y and return alist from x to y 1. If x y, it should return nil. For example,until (1, 4) should return [1,2,3].4. Write a function append that takes an integer x and a list of integers andreturn a list of pairs where the left of each pair is x and right of each pairis a list element. For example, append (1, [1, 2, 3]) should return[(1,1), (1,2), (1, 3)].15. Write a function pair that takes two lists of integers and generates a listof pairs, where each pair is a combination of each element from each list.For example, pair ([1,2], [3,4,5]) should return[(1,3), (1,4), (1,5), (2,3), (2,4), (2,5)].3 SubmissionPlease write your solution in a text le by the name of hwk3.sml and submit itto the dropbox.2
Reviews
There are no reviews yet.