Section nonmonadic.
Variables (T: Set) (le: T -> T -> bool).
Definition gt (x y: T): bool := negb (le x y).
Program Fixpoint qs (l: list T) {measure (length l) lt}: list T :=
match l with
| nil => nil
| pivot :: t => qs (filter (gt pivot) t) ++ (pivot :: nil) ++ qs (filter (le pivot) t)
end.
Next Obligation. simpl; auto with arith. Qed.
Next Obligation. simpl; auto with arith. Qed.
Definition body (l : list T) (qs0 : {l' : list T | length l' < length l} -> list T) :=
match l as l0 return (l0 = l -> list T) with
| nil => fun _ => nil
| pivot :: t0 => fun Heq_l =>
qs0 (exist (fun l' => length l' < length l) (filter (gt pivot) t0) (qs_obligation_1 (fun l H => qs0 (exist _ l H)) Heq_l)) ++
(pivot :: nil) ++
qs0 (exist (fun l' => length l' < length l) (filter (le pivot) t0) (qs_obligation_2 (fun l H => qs0 (exist _ l H)) Heq_l))
end refl_equal.
Proof with auto.
intros.
destruct x0...
simpl.
f_equal...
f_equal...
Qed.

Lemma unfold: forall l, qs l = Fix_sub (list T) (MR lt (fun l0 : list T => length l0)) qs_obligation_3 (fun _ : list T => list T) body l.