Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribed

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions