I am trying to implement a very trivial sorting algorithm in Haskell. It compiles but keeps giving me incorrect outputs.
Here is the code
import Data.List
minimum' :: (Ord a) => [a] -> a
minimum' (x:xs) = foldr (\ x y -> if x <= y then x else y) x xs
qsrt :: (Ord a) => [a] -> [a]
qsrt [] = []
qsrt l@(x:xs) = minimum' l : qsrt xs
Any thoughts?
qsrtwould sort the list? Which sorting algorithm are you trying to implement?qsrttakes the minimum element ofland then skipsx, butxwould only be the minimum element oflby accident so you're usually skipping the wrong element.let qsrt [] = []; qsrt l = let y = minimum' l in y : qsrt (delete y l)