@@ -16,6 +16,7 @@ import Prelude.Maybe
1616import Prelude.Monad
1717import Prelude.Nat
1818import Language.Reflection
19+import Language.Reflection.Errors
1920
2021%access public export
2122
@@ -138,6 +139,7 @@ data Elab : Type -> Type where
138139 Prim__BindElab : {a, b : Type} -> Elab a -> (a -> Elab b) -> Elab b
139140
140141 Prim__Try : {a : Type} -> Elab a -> Elab a -> Elab a
142+ Prim__TryCatch : {a : Type} -> Elab a -> (Err -> Elab a) -> Elab a
141143 Prim__Fail : {a : Type} -> List ErrorReportPart -> Elab a
142144
143145 Prim__Env : Elab (List (TTName, Binder TT))
@@ -218,6 +220,13 @@ namespace Tactics
218220 implementation Monad Elab where
219221 x >>= f = Prim__BindElab x f
220222
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.
226+ export
227+ tryCatch : Elab a -> (Err -> Elab a) -> Elab a
228+ tryCatch x f = Prim__TryCatch x f
229+
221230 ||| Halt elaboration with an error
222231 export
223232 fail : List ErrorReportPart -> Elab a