Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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
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 definitionStep 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