@@ -283,8 +283,8 @@ This captures the expected error propagation behavior in effectful computations.
283283theorem runEff_bind_err {α β}
284284 {p : FreeM Eff α} {k : α → FreeM Eff β}
285285 {env : Env} {tr : Trace} {msg : String} :
286- runEff p env tr = .error msg →
287- runEff (p >>= k) env tr = .error msg := by
286+ runEff p env tr = .error msg →
287+ runEff (p >>= k) env tr = .error msg := by
288288 induction p generalizing env tr msg <;> simp only [runEff, bind, foldFreeM] <;> intro h
289289 · case pure => simp [effPure] at h
290290 · case liftBind _ op _ ih =>
@@ -307,41 +307,41 @@ theorem runEff_eval_correct (e : Expr) (env : Env) (trace : Trace)
307307 (res : Except String (Int × Env × Trace))
308308 (h : EvalRel e env trace res) :
309309 runEff (eval e) env trace = res := by
310- induction h
311- · case val z env trace =>
312- simp [eval, pure_eq_pure, runEff, effPure]
313- · case var_found x env trace v h =>
314- simp [runEff, eval, getEnv, lift_def, effStep, h, effPure]
315- · case var_missing x env trace h =>
316- simp [runEff, eval, bind, getEnv, fail, lift_def, effStep, h]
317- · case add e₁ e₂ env trace₁ trace₂ trace₃ v1 v2 env₂ env₃ h₁ h₂ ih₁ ih₂ =>
318- simp [eval, bind]
319- have step₁ := runEff_bind_ok (p := eval e₁ ) (k := fun v1 => do
320- let v2 ← eval e₂
321- pure (v1 + v2)) ih₁
322- simp [bind] at step₁; simp [step₁]
323- have step₂ := runEff_bind_ok (p := eval e₂) (k := fun v2 => pure (v1 + v2)) ih₂
324- simp [bind] at step₂; simp [step₂]; rfl
325- · case div_ok e₁ e₂ env trace₁ trace₂ trace₃ v₁ v₂ env₂ env₃ v₂_ne_0 h₁ h₂ ih₁ ih₂ =>
326- simp [eval, bind]
327- have step₁ := runEff_bind_ok (p := eval e₁) (k := fun v1 => do
328- let v2 ← eval e₂
329- if v2 = 0 then do fail "divide by zero" ; pure 0 else pure (v1 / v2)) ih₁
330- simp [bind] at step₁; simp [step₁]
331- have step₂ := runEff_bind_ok (p := eval e₂) (k := fun v₂ =>
332- if v₂ = 0 then do fail "divide by zero" ; pure 0 else pure (v₁ / v₂)) ih₂
333- simp [bind] at step₂; simp [step₂, v₂_ne_0]
334- rfl
335- · case div_zero e₁ e₂ env' trace₁ trace₂ trace₃ v₁ v₂ env₂ env₃ v₂_eq_0 h₁ h₂ ih₁ ih₂ =>
336- simp [eval, bind]
337- have step₁ := runEff_bind_ok (p := eval e₁) (k := fun v₁ => do
338- let v₂ ← eval e₂
339- if v₂ = 0 then fail "divide by zero" ; pure 0 else pure (v₁ / v₂)) ih₁
340- simp [bind] at step₁; simp [step₁]
341- have step₂ := runEff_bind_ok (p := eval e₂) (k := fun v₂ =>
342- if v₂ = 0 then (do fail "divide by zero" ; pure 0 ) else pure (v₁ / v₂)) ih₂
343- simp [bind] at step₂; simp [step₂, v₂_eq_0]
344- simp [fail, lift, runEff]
345- rfl
310+ induction h
311+ · case val z env trace =>
312+ simp [eval, pure_eq_pure, runEff, effPure]
313+ · case var_found x env trace v h =>
314+ simp [runEff, eval, getEnv, lift_def, effStep, h, effPure]
315+ · case var_missing x env trace h =>
316+ simp [runEff, eval, bind, getEnv, fail, lift_def, effStep, h]
317+ · case add e₁ e₂ env trace₁ trace₂ trace₃ v1 v2 env₂ env₃ h₁ h₂ ih₁ ih₂ =>
318+ simp [eval, bind]
319+ have step₁ := runEff_bind_ok (p := eval e₁ ) (k := fun v1 => do
320+ let v2 ← eval e₂
321+ pure (v1 + v2)) ih₁
322+ simp [bind] at step₁; simp [step₁]
323+ have step₂ := runEff_bind_ok (p := eval e₂) (k := fun v2 => pure (v1 + v2)) ih₂
324+ simp [bind] at step₂; simp [step₂]; rfl
325+ · case div_ok e₁ e₂ env trace₁ trace₂ trace₃ v₁ v₂ env₂ env₃ v₂_ne_0 h₁ h₂ ih₁ ih₂ =>
326+ simp [eval, bind]
327+ have step₁ := runEff_bind_ok (p := eval e₁) (k := fun v1 => do
328+ let v2 ← eval e₂
329+ if v2 = 0 then do fail "divide by zero" ; pure 0 else pure (v1 / v2)) ih₁
330+ simp [bind] at step₁; simp [step₁]
331+ have step₂ := runEff_bind_ok (p := eval e₂) (k := fun v₂ =>
332+ if v₂ = 0 then do fail "divide by zero" ; pure 0 else pure (v₁ / v₂)) ih₂
333+ simp [bind] at step₂; simp [step₂, v₂_ne_0]
334+ rfl
335+ · case div_zero e₁ e₂ env' trace₁ trace₂ trace₃ v₁ v₂ env₂ env₃ v₂_eq_0 h₁ h₂ ih₁ ih₂ =>
336+ simp [eval, bind]
337+ have step₁ := runEff_bind_ok (p := eval e₁) (k := fun v₁ => do
338+ let v₂ ← eval e₂
339+ if v₂ = 0 then fail "divide by zero" ; pure 0 else pure (v₁ / v₂)) ih₁
340+ simp [bind] at step₁; simp [step₁]
341+ have step₂ := runEff_bind_ok (p := eval e₂) (k := fun v₂ =>
342+ if v₂ = 0 then (do fail "divide by zero" ; pure 0 ) else pure (v₁ / v₂)) ih₂
343+ simp [bind] at step₂; simp [step₂, v₂_eq_0]
344+ simp [fail, lift, runEff]
345+ rfl
346346
347347end CslibTests
0 commit comments