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.

Lemma body_eq:
forall (x0 : list T) (g h0 : {y : list T | length y < length x0} -> list T),
(forall (x : list T) (p p' : length x < length x0),
g (exist (fun y : list T => length y < length x0) x p) =
h0 (exist (fun y : list T => length y < length x0) x p')) ->
body x0 g = body x0 h0.