Section monadic.
Variables (M: Monad) (T: Set) (le: T -> T -> M bool).
Fixpoint insert (l: list T) (x: T): M (list T) :=
match l with
| nil => ret (x :: nil)
| h :: t =>
r <- le x h ;
if r
then ret (x :: h :: t)
else t' <- insert t x ; ret (h :: t')
end.

Lemma insert_unfold: forall l x, insert l x =
match l with
| nil => ret (x :: nil)
| h :: t =>
r <- le x h ;
if r then ret (x :: h :: t) else t' <- insert t x ; ret (h :: t')
end.