Module QcDoNotation.
Notation "'do!' X <- A ; B" :=
(bindGen A (fun X => B))
(at level 200, X ident, A at level 100, B at level 200).
Notation "'doM!' X <- A ; B" :=
(bindGenOpt A (fun X => B))
(at level 200, X ident, A at level 100, B at level 200).
End QcDoNotation.
(* CH: Reusing :: instead of ;; would have been nice, but I didn't manage *)
Instance bindOptMonotonicOpt
{A B} (g : G (option A)) (f : A -> G (option B))
`{SizeMonotonicOpt _ g} `{forall x, SizeMonotonicOpt (f x)} :
SizeMonotonicOpt (bindGenOpt g f).
Instance bindOptMonotonic
{A B} (g : G (option A)) (f : A -> G (option B))
`{SizeMonotonic _ g} `{forall x, SizeMonotonic (f x)} :
SizeMonotonic (bindGenOpt g f).
Definition GOpt A := G (option A).
Global Instance Monad_GOpt : Monad GOpt := {
ret A x := returnGen (Some x);
bind A B := bindGenOpt;
}.

Lemma semSize_retryBody {A} (n : nat) (g : G (option A)) (s : nat) :
match n with
| S n' => semGenSize (retry n' g) s <--> semGenSize g s
| O => True
end ->
semGenSize (retryBody retry n g) s <--> semGenSize g s.