local exception emptyList; (* findMin finds the minimum element in the list and removes it *) fun findMin [] = raise emptyList | findMin [h] = (h, []) | findMin (h::t) = let val (m, tt) = findMin t; in if m < h then (m, h::tt) else (h, t) end; in fun selSortFun [] = [] | selSortFun [h] = [h] | selSortFun (L as h::t) = let val (m, LL) = findMin L in m::(selSortFun LL) end; end val sf = selSortFun; sf [~12, ~24, ~12, 0, 123, 45, 1, 20, 0, ~24];