fix: for result type

This commit is contained in:
Leonardo de Moura 2020-10-12 10:38:32 -07:00
parent 611c77f7e9
commit 67e9c83f54
2 changed files with 19 additions and 2 deletions

View file

@ -843,8 +843,8 @@ ctx ← read;
u ← mkUVarTuple ref;
match ctx.kind with
| Kind.regular => if ctx.uvars.isEmpty then pure action else `(HasBind.bind $action fun y => HasPure.pure (y, $u))
| Kind.forIn => `(HasBind.bind $action fun _ => HasPure.pure (ForInStep.yield $u))
| Kind.forInWithReturn => `(HasBind.bind $action fun _ => HasPure.pure (ForInStep.yield (none, $u)))
| Kind.forIn => `(HasBind.bind $action fun (_ : PUnit) => HasPure.pure (ForInStep.yield $u))
| Kind.forInWithReturn => `(HasBind.bind $action fun (_ : PUnit) => HasPure.pure (ForInStep.yield (none, $u)))
| Kind.nestedBC => unreachable!
| Kind.nestedPR => `(HasBind.bind $action fun y => (HasPure.pure (DoResultPR.«pure» y $u)))
| Kind.nestedSBC => `(HasBind.bind $action fun y => (HasPure.pure (DoResultSBC.«pureReturn» y $u)))

View file

@ -0,0 +1,17 @@
new_frontend
abbrev M := ExceptT String $ StateT Nat Id
def f (xs : List Nat) : M Unit := do
for x in xs do
if x == 0 then
throw "contains zero"
#eval f [1, 2, 3] $.run' 0
#eval f [1, 0, 3] $.run' 0
theorem ex1 : f [1, 2, 3] $.run' 0 = Except.ok () :=
rfl
theorem ex2 : f [1, 0, 3] $.run' 0 = Except.error "contains zero" :=
rfl