better comments/documentation
[coinductive-monad.git] / src / Computation / Eval.v
1 Require Export Computation.Monad.
2 Require Export Computation.Termination.
3
4 (** evaluate up to [n] computation steps *)
5 Fixpoint bounded_eval (A:Set) (n:nat) (c:#A) {struct n} : option A :=
6   match n with
7     | O      => None
8     | (S n') =>
9       match c with
10         | Return b   => Some b
11         | Bind _ f c' =>
12           match (bounded_eval _ n' c') with
13             | None   => None
14             | Some a => bounded_eval A n' (f a)
15           end
16       end
17   end.
18
19 (** In theory we'd like to be able to do this (below), but it violates the Prop/Set separation.
20  *)
21 (**
22 <<
23 Definition eval (A:Set) (c:#A) (t:Terminates c) : A :=
24   match t with
25     | (Terminates_intro t') =>
26       match t' with
27         | (ex_intro x y) => x
28       end
29   end.
30  
31  "Elimination of an inductive object of sort Prop is not allowed on a
32   predicate in sort Set because proofs can be eliminated only to
33   build proofs."
34 >>*)
35
36 Inductive Unit : Set := unit : Unit.
37 Definition eval (A:Set) (c:#A) (t:Terminates c) : A :=
38   match eval' c Unit (Return unit) (termination_is_safe A c t) with
39     | exist x pf => x
40   end.
41
42 Implicit Arguments eval [A].
43 Implicit Arguments bounded_eval [A].
44