<div dir="ltr"><div>I am posting the same question again because I had not subscribed to the list and I received a message saying it was automatically rejected.</div><div><br></div>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.<div>So, if the list is sorted, then the list will remain sorted.<br><div><div><br></div><div><div style="border-width: 1px; border-style: solid; border-color: rgb(187, 187, 187); background-color: rgb(250, 250, 250); word-wrap: break-word;"><code><div>myInsert :: Ord a => a -> [a] -> [a]</div><div>myInsert x [] = [x]</div><div>myInsert x (y:ys) = if x < y then x:y:ys else y:myInsert x ys</div></code></div><br>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:</div></div></div><div><br></div><div><div style="border-width: 1px; border-style: solid; border-color: rgb(187, 187, 187); background-color: rgb(250, 250, 250); word-wrap: break-word;"><code><div>insertionSort :: Ord a => [a] -> [a]</div><div>insertionSort [] = []</div><div>insertionSort [x] = [x]</div><div>insertionSort (x:xs) = myInsert x (insertionSort xs)</div></code></div><div><br></div>I have worked for 2 days to use foldr without success, for example:<br></div><div><br></div><div><div style="border-width: 1px; border-style: solid; border-color: rgb(187, 187, 187); background-color: rgb(250, 250, 250); word-wrap: break-word;"><code><div>insertionSort :: Ord a => [a] -> [a]</div><div>insertionSort [] = []</div><div>insertionSort [x] = [x]</div><div><span style="font-family: Arial, Helvetica, sans-serif;">insertionSort (x:xs) = foldr (myInsert) x (insertionSort xs)</span></div></code></div><div><br></div>But it does not even compile, I get the following error which refers to last instruction at position "x" in "<span style="background-color: rgb(250, 250, 250);">foldr (myInsert) x (insertionSort xs)":</span></div><div><br></div><div><span style="background-color: rgb(255, 255, 0);">Couldn't match expected type ‘[a]’ with actual type ‘a’</span></div><div><br></div><div>I will very much appreciate your feedback in order to solve my issue.</div><div><br></div><div>Best regards.</div></div>