@@ -16,6 +16,7 @@ import Prelude.Maybe
16import Prelude.Monad
16import Prelude.Monad
17import Prelude.Nat
17import Prelude.Nat
18import Language.Reflection
18import Language.Reflection
19+import Language.Reflection.Errors
20%access public export
21%access public export
@@ -138,6 +139,7 @@ data Elab : Type -> Type where
138 Prim__BindElab : {a, b : Type} -> Elab a -> (a -> Elab b) -> Elab b
139 Prim__BindElab : {a, b : Type} -> Elab a -> (a -> Elab b) -> Elab b
140 Prim__Try : {a : Type} -> Elab a -> Elab a -> Elab a
141 Prim__Try : {a : Type} -> Elab a -> Elab a -> Elab a
142+ Prim__TryCatch : {a : Type} -> Elab a -> (Err -> Elab a) -> Elab a
141 Prim__Fail : {a : Type} -> List ErrorReportPart -> Elab a
143 Prim__Fail : {a : Type} -> List ErrorReportPart -> Elab a
143 Prim__Env : Elab (List (TTName, Binder TT))
145 Prim__Env : Elab (List (TTName, Binder TT))
@@ -218,6 +220,13 @@ namespace Tactics
218 implementation Monad Elab where
220 implementation Monad Elab where
219 x >>= f = Prim__BindElab x f
221 x >>= f = Prim__BindElab x f
223+ ||| `tryCatch t (\err => t')` will run `t`, and if it
224+ ||| fails, roll back the elaboration state and run `t'`,
225+ ||| but with access to the knowledge of why `t` failed.
227+ tryCatch : Elab a -> (Err -> Elab a) -> Elab a
228+ tryCatch x f = Prim__TryCatch x f
221 ||| Halt elaboration with an error
230 ||| Halt elaboration with an error
223 fail : List ErrorReportPart -> Elab a
232 fail : List ErrorReportPart -> Elab a