** This is most probably some pedagogic assignment, and you should not expect from the community to solve your exercices.I have the following function that takes an element and a list and inserts the element into the list at the first position where it is less than or equal to the next element.
OK....
myInsert :: Ord a => a -> [a] -> [a]myInsert x [] = [x]myInsert x (y:ys) = if x < y then x:y:ys else y:myInsert x ys
Now, I have to use the above function myInsert and foldr to implement another function called insertionSort. I have been able to do it without using foldr as follows and it works just fine:
I have worked for 2 days to use foldr without success, for example:
insertionSort :: Ord a => [a] -> [a]insertionSort [] = []insertionSort [x] = [x]insertionSort (x:xs) = foldr (myInsert) x (insertionSort xs)But it does not even compile, I get the following error which refers to last instruction at position "x" in "foldr (myInsert) x (insertionSort xs)":
Couldn't match expected type ‘[a]’ with actual type ‘a’