(* Two Way Sort The following program sorts an array of Boolean values, with False a[i1] << a[i2] let two_way_sort (a: array bool) : unit ensures { true } = 'Init: let i = ref 0 in let j = ref (length a - 1) in while !i < !j do invariant { true } if not a[!i] then incr i else if a[!j] then decr j else begin swap a !i !j; incr i; decr j end done end