[SOLVED] CS 431 Programming language concepts Homework 3

30.00 $

Programming resource
Digital learning resource
Category:
✓ Practical programming resource
✓ Suitable for guided study and reference
✓ Tutor guidance available when needed

Description

Rate this product

Homework 3

1 Introduction
For this homework, you will implement some SML functions using list and tuple
data structures.
1. You may reuse any functions you have already de ned for a previous
question.
2. Your solution should be a working ML program in a text le that I can
run 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 Questions
1. Write a function plus that adds two complex numbers, where a complex
number is written as a tuple of two integers. For example, (1; 2) is a
complex 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 a
list 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 and
return a list of pairs where the left of each pair is x and right of each pair
is a list element. For example, append (1, [1, 2, 3]) should return
[(1,1), (1,2), (1, 3)].
1
5. Write a function pair that takes two lists of integers and generates a list
of 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 Submission
Please write your solution in a text le by the name of hwk3.sml and submit it
to the dropbox.
2

Resource details

Understand the Task Before You Use the Resource

Review the requirements, identify the programming concepts involved, study the implementation and test your understanding with your own examples and modifications.