f :: [Int] -> [Int] f xs = let (m, ys) = replace_with_min m xs in ys where -- replace elements with min and return the tuple of min and replaced list replace_with_min :: Int -> [Int] -> (Int, [Int]) replace_with_min m [] = (m, []) replace_with_min m [x] = (x, [m]) replace_with_min m (x : xs) = let (m', xs') = replace_with_min m xs in (min x m', m : xs')