PLEASE FOLLOW DIRECTIONS IN HASKELL write mergeSort code to take a function as a parameter and use the function to defin
Posted: Sat May 14, 2022 7:53 pm
PLEASE FOLLOW DIRECTIONS
IN HASKELL write mergeSort code to
take a function as a parameter and use the function to define the
sort order.
a) Write a lambda expression that takes two Orderables and
returns true if the first one is less than or equal to the second
one, and otherwise returns false. I will refer to this lambda
expression below as l1. Then write one that takes two Orderables
and does just the opposite. I will refer to this one as l2.
b) In the merge function, instead of testing whether the first
value in xs is less than or equal to the first value in ys, apply
the function expression to the two values. This will require
several additional changes to the code for both merge and
mergeSort. Hint: the function signature for merge will be
merge :: Ord a => [a] -> [a] -> (a -> a -> Bool)
-> [a]
merge xs ys l
where (a -> a -> a) signifies a function that takes two
values of type a and returns a Boolean.
c) Write testing code mergeSort. If you call
mergeSort and send lambda expression l1, it should return a new
list sorted in ascending order. If you call it with lambda
expression l2, it should return a list sorted in descending
order.
Paste your code, including your test code, and the output from
the tests here: using your lambda expressions l1 and l2
IN HASKELL write mergeSort code to
take a function as a parameter and use the function to define the
sort order.
a) Write a lambda expression that takes two Orderables and
returns true if the first one is less than or equal to the second
one, and otherwise returns false. I will refer to this lambda
expression below as l1. Then write one that takes two Orderables
and does just the opposite. I will refer to this one as l2.
b) In the merge function, instead of testing whether the first
value in xs is less than or equal to the first value in ys, apply
the function expression to the two values. This will require
several additional changes to the code for both merge and
mergeSort. Hint: the function signature for merge will be
merge :: Ord a => [a] -> [a] -> (a -> a -> Bool)
-> [a]
merge xs ys l
where (a -> a -> a) signifies a function that takes two
values of type a and returns a Boolean.
c) Write testing code mergeSort. If you call
mergeSort and send lambda expression l1, it should return a new
list sorted in ascending order. If you call it with lambda
expression l2, it should return a list sorted in descending
order.
Paste your code, including your test code, and the output from
the tests here: using your lambda expressions l1 and l2