Bubble sort in Haskell
Here's your shortening including a fold.

bubbleSort :: Ord a =&gt; [a] -&gt; [a]
bubbleSort xs = foldr swapTill xs [1..length xs-1]

swapTill :: Ord a =&gt; Int -&gt; [a] -&gt; [a]
swapTill 0 = id
swapTill count = \(x:y:xs) -&gt; min x y : swapTill (count-1) (max x y:xs)


Reordering the swaps to sort a growing suffix of the list banishes Int.

bubbleSort :: Ord a =&gt; [a] -&gt; [a]
bubbleSort = foldr swapTill []

swapTill x [] = [x]
swapTill x (y:xs) = min x y : swapTill (max x y) xs