test: monad stack with multiple ExceptT

cc @Kha :)
This commit is contained in:
Leonardo de Moura 2020-10-08 19:53:12 -07:00
parent 8a6cb1842f
commit f6fffc9532

View file

@ -0,0 +1,29 @@
new_frontend
abbrev M := ExceptT String $ ExceptT Nat $ StateM Nat
def inc (x : Nat) : M Unit := do
if (← get) >= 100 then
throwThe Nat ((← get) + x)
modify (· + x)
def dec (x : Nat) : M Unit := do
if (← get) - x == 0 then
throw "balance is zero"
modify (· - x)
def f (x y : Nat) : M Nat := do
try
inc x
dec y
get
catch ex : String =>
dbgTrace! "string exception " ++ toString ex
pure 1000
catch ex : Nat =>
dbgTrace! "nat exception " ++ toString ex
pure ex
#eval (f 10 20).run 1000
#eval (f 10 200).run 10
#eval (f 10 20).run 30