orderedInsert :: (Ord a) => [a] -> a -> [a] orderedInsert [] x = [x] orderedInsert (x : xs) y = if y <= x then y : x : xs else x : orderedInsert xs y insertionSort :: (Ord a) => [a] -> [a] insertionSort = foldl orderedInsert []