Seunghyun Yoo

Posts | Development | About

[EN] 4 lines of insertion sort (OCaml)

The importance of a concise language design:

let rec insert lst x = match lst with 
	| [] -> [x]
	| h::t -> if h < x then h::(insert t x) else x::lst;;
let insertion_sort lst = List.fold_left insert [] lst;;
let v = insertion_sort [5; 3; 2; 4; 1];;