Skip to content

Instantly share code, notes, and snippets.

@david-christiansen
Created January 23, 2014 15:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save david-christiansen/8580625 to your computer and use it in GitHub Desktop.
Save david-christiansen/8580625 to your computer and use it in GitHub Desktop.
Error reflection now supports specific function arguments
import Language.Reflection.Errors
import Language.Reflection.Utils
%language ErrorReflection
total
cadr : (xs : List a)
-> {auto cons1 : isCons xs = True}
-> {auto cons2 : isCons (tail xs cons1) = True}
-> a
cadr (x :: (y :: _)) {cons1=refl} {cons2=refl} = y
cadr (x :: []) {cons1=refl} {cons2=refl} impossible
extractList : TT -> Maybe TT
extractList (App (App reflCon (App isCons lst)) _) = Just lst
extractList _ = Nothing
total
has2elts : Err -> Maybe (List ErrorReportPart)
has2elts (CantSolveGoal tm _) = do lst <- extractList tm
return [ TextPart "Could not prove that"
, TermPart lst
, TextPart "has at least two elements."
]
has2elts e = Just [TextPart (show e)]
%error_handlers cadr cons1 has2elts
%error_handlers cadr cons2 has2elts
*FunErrTest> cadr []
Could not prove that [] has at least two elements.
Original error:
Can't solve goal
isCons [] = True
*FunErrTest> \ xs : List Int => cadr xs
Could not prove that xs has at least two elements.
Original error:
Can't solve goal
isCons xs = True
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment