Question: USING HASKELL 1. (4 points) Define a recursive function mergeBy that merges two sorted lists by the given criterion, for example, in an ascending order

USING HASKELL

USING HASKELL 1. (4 points) Define a recursive function mergeBy that merges

1. (4 points) Define a recursive function mergeBy that merges two sorted lists by the given criterion, for example, in an ascending order or in a descending order (so that the resulting list is also sorted). Type signature of mergeBy is as follows mergeBy:: (a -> a -> Bool) -> [a] -> [a] -> a] Notice the difference from merge :: Ord a=> [a] -> [a] -> [a] in Ch.6 Exercise 7, in that mergeBy accepts three arguments, the first of which is a comparison function of type (a ->a - Bool) that determines in which way the list is to be sorted. Such comparison function that returns a Boolean value (true or false) is called a predicate. 2. (4 points) Explain your mergeBy function definition. 3. (4 points) Using mergeBy that you wrote above and halve that you wrote for Problem8 in Assignment 1, define a recursive function msortBy. The problem specification stays the same as that for msort in Ch. 6 Exercise 8, except the additional requirement of the first argument being a predicate. Thus, the type of msortBy is: msortBy:: (a -> a -Bool) -[a] -> [a] 4. (3 points) Explain your msortBy function definition. 1. (4 points) Define a recursive function mergeBy that merges two sorted lists by the given criterion, for example, in an ascending order or in a descending order (so that the resulting list is also sorted). Type signature of mergeBy is as follows mergeBy:: (a -> a -> Bool) -> [a] -> [a] -> a] Notice the difference from merge :: Ord a=> [a] -> [a] -> [a] in Ch.6 Exercise 7, in that mergeBy accepts three arguments, the first of which is a comparison function of type (a ->a - Bool) that determines in which way the list is to be sorted. Such comparison function that returns a Boolean value (true or false) is called a predicate. 2. (4 points) Explain your mergeBy function definition. 3. (4 points) Using mergeBy that you wrote above and halve that you wrote for Problem8 in Assignment 1, define a recursive function msortBy. The problem specification stays the same as that for msort in Ch. 6 Exercise 8, except the additional requirement of the first argument being a predicate. Thus, the type of msortBy is: msortBy:: (a -> a -Bool) -[a] -> [a] 4. (3 points) Explain your msortBy function definition

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!