Section RandomFunc.
Variable D R : Set.
Hypothesis D_EqDec : EqDec D.
Hypothesis R_EqDec : EqDec R.
Variable RndR : Comp R.
Hypothesis RndR_wf : well_formed_comp RndR.
(* A random function *)
Definition randomFunc(p : (list (D * R)) * D) : Comp (list (D * R) * R) :=
let (f, d) := p in
match (arrayLookup _ f d) with
| None => (r <-$ RndR; ret ((d, r) :: f, r))
| Some r => ret (f, r)
end.
intuition.
unfold randomFunc.
case_eq (a#b); intuition; wftac.
Qed.
(* Eager random functions can be used to simplify many definitions. *)
Fixpoint randomFunc_eager_arr(allD : list D) :=
match allD with
| nil => ret nil
| d :: allD' =>
arr' <-$ randomFunc_eager_arr allD';
r <-$ RndR;
ret ((d, r) :: arr')
end.
Hint Resolve randomFunc_wf : wftac.

Theorem inSupportRandomFunc :
forall a b r,
a # b = None ->
In r (getSupport RndR) ->
In ((b, r) :: a, r) (getSupport (randomFunc (a, b))).