Answered step by step
Verified Expert Solution
Link Copied!

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

image text in transcribed

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

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

Question

1. What is the tone of the comments? How can they be improved?

Answered: 1 week ago

Question

b. Explain how you initially felt about the communication.

Answered: 1 week ago

Question

3. Identify the methods used within each of the three approaches.

Answered: 1 week ago

Question

a. When did your ancestors come to the United States?

Answered: 1 week ago