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 semSizeOpt_suchThatMaybe {A : Type} (g : G A) (p : A -> bool)
(s : nat) :
semGenSizeOpt (suchThatMaybe g p) s <--> semGenSize g s :&: p.