Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

ml functions Write an ML function qsort which, given a list of objects l and a c

ID: 640801 • Letter: M

Question

ml functions

Write an ML function qsort which, given a list of objects l and a comparator function f (given curry in curry style, f has type ?a ? > ?a ? > bool) outputs a sorted version of l in ascending order according to f using the classic quicksort algorithm. Note that we are well aware of the Wikipedia implementation or the other dozen implementations floating on the web. I expect you to write this on your own! Namely, write fun qsort 1 f = ... Revisit the previous question, hut this time, you cannot define the partition from first principles (as a recursive function) nor can you use the List.partition basis function. The only thing you can use is the higher-order function foldr. fun qsHigh 1f = ...

Explanation / Answer

val filt = List.filter fun qsort