[Solved] CS 431 Programming language concepts Homework 4 solved

$25

File Name: CS_431_Programming_language_concepts_Homework_4_solved.zip
File Size: 508.68 KB

SKU: [Solved] CS 431 Programming language concepts Homework 4 solved Category: Tag:
5/5 - (1 vote)

Homework 41 IntroductionFor this homework, you will implement some SML functions using patternmatching.1. Your solution should be a working ML program in a text le that I canrun on a console using command like use hwk4.sml;2. You may add comments to your program such as (* Question 1 *).3. Use `let expression as necessary for local variables and local functions.2 Questions1. Write a function zip that takes two lists and return a list of 2-tuples.For example, zip ([1, 2, 3], [4, 5]) should return [(1,4), (2,5)].Note that if one list is longer than the other, the unmatched portion ofthe longer list is ignored.2. Write a function unzip that takes a list of 2-tuples and return a tupleof two lists. For example, unzip [(1,2), (3,4), (5,6)] should return([1,3,5], [2,4,6]).3. Write a function zip3 that takes three lists and return a list of 3-tuples.For example, zip3 ([1, 2, 3], [4, 5], [6,7,8]) should return [(1,4,6), (2,5,7)].Note that if one list is longer than the others, the unmatched portion ofthe longer list is ignored.4. Write a function unzip3 that takes a list of 3-tuples and return a tuple ofthree lists. For example, unzip3 [(1,2,3), (4,5,6), (7,8,9)] shouldreturn ([1,4,7], [2,5,8], [3,6,9]).5. Write a function zipWithIndex that takes a list and return a list of 2-tuples, where each tuple contains an index and a list element. For example,zipWithIndex [a, b, c] should return [(0, a), (1, b), (2, c)].16. Write a function flatten that takes a list of lists and return a at-tened list. For example, flatten [[1,2], [3], [4,5,6]] should return[1,2,3,4,5,6].7. Write a function flatten2 that takes a list of 2-tuples and return a at-tened list. For example, flatten2 [(1,2), (3,4), (5,6)] should re-turn [1,2,3,4,5,6].3 SubmissionPlease write your solution in a text le by the name of hwk4.sml and submit itto the dropbox.2

Reviews

There are no reviews yet.

Only logged in customers who have purchased this product may leave a review.

Shopping Cart
[Solved] CS 431 Programming language concepts Homework 4 solved[Solved] CS 431 Programming language concepts Homework 4 solved
$25