Question: USING HASKELL Problem 4. (20 points) This problem has two parts 1. (8 points) Using guarded equations, implement a function myInsert that behaves the same
USING HASKELL

Problem 4. (20 points) This problem has two parts 1. (8 points) Using guarded equations, implement a function myInsert that behaves the same way as the insert function defined in Data.List package. The Data.List.insert function takes an element and a list and inserts the element into the list at the first position where it is less than or equal to the next element. In particular, if the list is sorted before the call, the result will also be sorted myInsert :: Ord a => a-> [a] -> [a] 2. (4 points) Explain your myInsert function definition 3. (3 points) Using myInsert and foldr, implement insertion sort (named mySort) mySort : : Ord a=> [a] -> [a] 4. (5 points) Explain how your mySort works when it is applied as below. Your explanation should be closely related to how foldr works > mySort [3,1,4,2,5] Problem 4. (20 points) This problem has two parts 1. (8 points) Using guarded equations, implement a function myInsert that behaves the same way as the insert function defined in Data.List package. The Data.List.insert function takes an element and a list and inserts the element into the list at the first position where it is less than or equal to the next element. In particular, if the list is sorted before the call, the result will also be sorted myInsert :: Ord a => a-> [a] -> [a] 2. (4 points) Explain your myInsert function definition 3. (3 points) Using myInsert and foldr, implement insertion sort (named mySort) mySort : : Ord a=> [a] -> [a] 4. (5 points) Explain how your mySort works when it is applied as below. Your explanation should be closely related to how foldr works > mySort [3,1,4,2,5]
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
