X-Git-Url: http://git.megacz.com/?p=coinductive-monad.git;a=blobdiff_plain;f=Computation%2FEval.v;fp=Computation%2FEval.v;h=07d79e4d104a8df9b9e0a364820dbd4b0f78f704;hp=0000000000000000000000000000000000000000;hb=ad8905d391e4e2015b6525a81a3b5e1ad607439e;hpb=7439e43c33a10817e19e7a5f26435d2097dc262d diff --git a/Computation/Eval.v b/Computation/Eval.v new file mode 100644 index 0000000..07d79e4 --- /dev/null +++ b/Computation/Eval.v @@ -0,0 +1,26 @@ +Require Export Computation.Monad. +Require Export Computation.Termination. + +(* evaluate up to [n] computation steps *) +Fixpoint bounded_eval (A:Set) (n:nat) (c:#A) {struct n} : option A := + match n with + | O => None + | (S n') => + match c with + | Return b => Some b + | Bind _ f c' => + match (bounded_eval _ n' c') with + | None => None + | Some a => bounded_eval A n' (f a) + end + end + end. + +Inductive Unit : Set := unit : Unit. +Definition eval (A:Set) (c:#A) (t:Terminates c) : A := + match eval' c Unit (Return unit) (termination_is_safe A c t) with + | exist x pf => x + end. + +Implicit Arguments eval [A]. +Implicit Arguments bounded_eval [A].