@@ -1,6 +1,7 @@
1module Data.Fin
1module Data.Fin
3%default total
3%default total
5||| Numbers strictly less than some bound. The name comes from "finite sets".
6||| Numbers strictly less than some bound. The name comes from "finite sets".
@@ -144,18 +145,47 @@ fromInteger {n} x {prf} with (integerToFin x n)
145%language ErrorReflection
146%language ErrorReflection
148+||| Attempt to convert a reflected (fromInteger n) to a Nat
150+getNat' : TT -> Maybe TT
151+getNat' `(fromInteger ~(TConst (BI c)) : Nat) = Just $ quote (the Nat (fromInteger c))
154+||| Attempt to convert a reflected (fromInteger n) to a Nat. Return
155+||| the original term on failure.
158+getNat tm = maybe tm id $ getNat' tm
161+mkFinIntegerErr : TT -> TT -> List ErrorReportPart -> Maybe (List ErrorReportPart)
162+mkFinIntegerErr lit finSize subErr
163+ = Just [ TextPart "When using", TermPart lit
164+ , TextPart "as a literal for a"
165+ , TermPart `(Fin ~(getNat finSize))
148finFromIntegerErrors : Err -> Maybe (List ErrorReportPart)
169finFromIntegerErrors : Err -> Maybe (List ErrorReportPart)
170+finFromIntegerErrors (CantUnify x tm `(IsJust (integerToFin ~(TConst c) ~m)) err xs y)
171+ = mkFinIntegerErr (TConst c) m
172+ [ TermPart (TConst c)
173+ , TextPart "is not strictly less than"
174+ , TermPart (getNat m)
176+finFromIntegerErrors (CantUnify x tm `(IsJust (integerToFin ~(P Bound n t) ~m)) err xs y)
177+ = mkFinIntegerErr (P Bound n t) m
178+ [ TextPart "Could not show that", TermPart (P Bound n t)
179+ , TextPart "is less than", TermPart (getNat m)
180+ , TextPart "because", TermPart (P Bound n t)
181+ , TextPart "is a bound variable instead of a constant"
182+ , TermPart (TConst (AType (ATInt ITBig)))
149finFromIntegerErrors (CantUnify x tm `(IsJust (integerToFin ~n ~m)) err xs y)
184finFromIntegerErrors (CantUnify x tm `(IsJust (integerToFin ~n ~m)) err xs y)
150− = Just [ TextPart "When using", TermPart n
185+ = mkFinIntegerErr n m
151− , TextPart "as a literal for a"
152− , TermPart `(Fin ~m)
153− , SubReport [ TextPart "Could not show that"
186+ [ TextPart "Could not show that" , TermPart n
155− , TextPart "is less than"
187+ , TextPart "is less than" , TermPart (getNat m)
159finFromIntegerErrors _ = Nothing
189finFromIntegerErrors _ = Nothing
161%error_handlers Data.Fin.fromInteger prf finFromIntegerErrors
191%error_handlers Data.Fin.fromInteger prf finFromIntegerErrors