(* Copyright 2012-2015 by Adam Petcher.				* * Use of this source code is governed by the license described	* * in the LICENSE file at the root of the source tree.		*)
(* The syntax of computations.  *)
Set Implicit Arguments.
Require Export Bvector.
Require Export List.
Require Export FCF.Blist.
Require Export FCF.EqDec.
Inductive Comp : Set -> Type :=
| Ret : forall (A : Set), eq_dec A -> A -> Comp A
| Bind : forall (A B : Set), Comp B -> (B -> Comp A) -> Comp A
| Rnd : forall n, Comp (Bvector n)
| Repeat : forall (A : Set), Comp A -> (A -> bool) -> Comp A.
(* syntactic equality for Comp *)
Inductive Comp_eq : forall (A : Set), Comp A -> Comp A -> Prop :=
| Comp_eq_Ret : forall (A : Set)(pf1 pf2 : eq_dec A)(a : A),
Comp_eq (Ret pf1 a) (Ret pf2 a)
| Comp_eq_Bind : forall (A B : Set)(c1x c1y : Comp B)(c2x c2y : B -> Comp A),
Comp_eq c1x c1y ->
(forall b, (Comp_eq (c2x b) (c2y b))) ->
Comp_eq (Bind c1x c2x) (Bind c1y c2y)
| Comp_eq_Rnd : forall n,
Comp_eq (Rnd n) (Rnd n)
| Comp_eq_Repeat : forall (A : Set)(c1 c2 : Comp A)(P1 P2 : A -> bool),
Comp_eq c1 c2 ->
(forall a, P1 a = P2 a) ->
Comp_eq (Repeat c1 P1) (Repeat c2 P2).
Hint Constructors Comp_eq : comp.
induction c; intuition; eauto with comp.
Qed.
induction n; intuition.
econstructor.
econstructor.
econstructor.
eapply IHn.
Qed.
induction 1; intuition;
eauto using Bvector_exists.
Qed.

Lemma comp_EqDec : forall (A : Set),
Comp A ->
EqDec A.