Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Below are two parts of sml file. Need to edit code to follow the exercise 11 and 1.2. Exercise 11 corresponds with 1.1 code below
Below are two parts of sml file. Need to edit code to follow the exercise 11 and 1.2. Exercise 11 corresponds with 1.1 code below and Exercise 1.2 corresponds with 1.2 code. Exercise 1.1: Write a function twiddle that takes as input a list of triples, and returns a list of pairs where each triple from the input has its middle element removed and its first and third elements swapped. Write this using pattern matching. Exercise 1.2: Write a function flipper that flips alternate elements from a list. So if the input list is (al, a2, a3, a4 a5, a6), then the output list should be (a2 a1, a4, a3, a6, a5]. If the length of the input list is odd, then the last element of the input list should also be the last element of the output list. Write this using pattern matching and the cons operator. (Below implement sets as lists.) (11) (* Write a function to test whether an element is a member of a set.) fun memberSet (...) = false | mernberSet (headtail, element) = if head = element then true else memberSet (tail, elemento (* 1.2 ( Write a function to construct the union of two sets. fun consUnion (0 set2) = set2 consunion (seti. D) = seti Icons Union (set) set2) = let fun unionHelper (1. 1. union) = union unionHelper (1) headistail, union if memberSet (union, head) then unionHelper tal union else union Helper.tail, headtunion) unionHelper (seti, set2_) - union Helper il set2, seti unionHelperseth setz) end hi Below are two parts of sml file. Need to edit code to follow the exercise 11 and 1.2. Exercise 11 corresponds with 1.1 code below and Exercise 1.2 corresponds with 1.2 code. Exercise 1.1: Write a function twiddle that takes as input a list of triples, and returns a list of pairs where each triple from the input has its middle element removed and its first and third elements swapped. Write this using pattern matching. Exercise 1.2: Write a function flipper that flips alternate elements from a list. So if the input list is (al, a2, a3, a4 a5, a6), then the output list should be (a2 a1, a4, a3, a6, a5]. If the length of the input list is odd, then the last element of the input list should also be the last element of the output list. Write this using pattern matching and the cons operator. (Below implement sets as lists.) (11) (* Write a function to test whether an element is a member of a set.) fun memberSet (...) = false | mernberSet (headtail, element) = if head = element then true else memberSet (tail, elemento (* 1.2 ( Write a function to construct the union of two sets. fun consUnion (0 set2) = set2 consunion (seti. D) = seti Icons Union (set) set2) = let fun unionHelper (1. 1. union) = union unionHelper (1) headistail, union if memberSet (union, head) then unionHelper tal union else union Helper.tail, headtunion) unionHelper (seti, set2_) - union Helper il set2, seti unionHelperseth setz) end hi
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started