Question: write haskell code for the following Exercise 4. Higher-order functions and sorting -5+7+6+5=23 points In Haskell, we can implement quick sort as follows. qsort 0

write haskell code for the following write haskell code for the following Exercise 4. Higher-order functions and sorting

Exercise 4. Higher-order functions and sorting -5+7+6+5=23 points In Haskell, we can implement quick sort as follows. qsort 0 = 0) qsort (x:xs) - quort (filter (- x) xs) (a) The qsort can sort Integers, Chars, Strings, and anything can be ordered. The limitation, however, is that sort always sorts inputs in the increasing order. In many situations, we need to sort inputs in the decreasing order. Define a function qsortDec that sorts inputs in the decreasing order. Note, you should not use the function reverse. (b) The issue with qsort and qsortDec is that they are highly repetitive. Our goal here is to reduce such repetition through higher-order functions (abstractions). We start by observing that the only places that qsort and qsortDec differ are the ways they compare elements. Motivated by this observation, our idea is to abstract out the comparison and represent it as a parameter. Please fill in the blanks with underlines below to define the qsortBy function. qsortBy :: -> [a] => [a] qsortBy compt) - qsortBy comp (y:ys) - qsortBy comp (filter (\x> ++ [y] ++ qsortBy comp (filter (\* -> - CSCE 550, Spring 2020, Homework ! (e) With sortBy, we can implement qsort and quortDee thronth it. Clive the definitions for quort and quortDec. To avoid name conflicts we have renamed the function names to qsort' and qsort Dec. respectively, (d) The function qsort By sive us a lot of expressiveness. For example, we can easily define a function orderByOccrs that orders bags by the mimber of occurrences of elements. As an example orderByOcere ca.5).(1.2)) -- [('b',2).('a',5))

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!