@@ -144,12 +144,25 @@ fromInteger {n} x {prf} with (integerToFin x n)
144 fromInteger {n} x {prf = ItIsJust} | Just y = y
144 fromInteger {n} x {prf = ItIsJust} | Just y = y
146%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
147total private
160total private
148mkFinIntegerErr : TT -> TT -> List ErrorReportPart -> Maybe (List ErrorReportPart)
161mkFinIntegerErr : TT -> TT -> List ErrorReportPart -> Maybe (List ErrorReportPart)
149mkFinIntegerErr lit finSize subErr
162mkFinIntegerErr lit finSize subErr
150 = Just [ TextPart "When using", TermPart lit
163 = Just [ TextPart "When using", TermPart lit
151 , TextPart "as a literal for a"
164 , TextPart "as a literal for a"
152− , TermPart `(Fin ~finSize)
165+ , TermPart `(Fin ~(getNat finSize))
153 , SubReport subErr
166 , SubReport subErr
@@ -158,12 +171,12 @@ finFromIntegerErrors (CantUnify x tm `(IsJust (integerToFin ~(TConst c) ~m)) err
158 = mkFinIntegerErr (TConst c) m
171 = mkFinIntegerErr (TConst c) m
159 [ TermPart (TConst c)
172 [ TermPart (TConst c)
160 , TextPart "is not strictly less than"
173 , TextPart "is not strictly less than"
161− , TermPart m
174+ , TermPart (getNat m)
163finFromIntegerErrors (CantUnify x tm `(IsJust (integerToFin ~(P Bound n t) ~m)) err xs y)
176finFromIntegerErrors (CantUnify x tm `(IsJust (integerToFin ~(P Bound n t) ~m)) err xs y)
164 = mkFinIntegerErr (P Bound n t) m
177 = mkFinIntegerErr (P Bound n t) m
165 [ TextPart "Could not show that", TermPart (P Bound n t)
178 [ TextPart "Could not show that", TermPart (P Bound n t)
166− , TextPart "is less than", TermPart m
179+ , TextPart "is less than", TermPart (getNat m)
167 , TextPart "because", TermPart (P Bound n t)
180 , TextPart "because", TermPart (P Bound n t)
168 , TextPart "is a bound variable instead of a constant"
181 , TextPart "is a bound variable instead of a constant"
169 , TermPart (TConst (AType (ATInt ITBig)))
182 , TermPart (TConst (AType (ATInt ITBig)))
@@ -171,7 +184,7 @@ finFromIntegerErrors (CantUnify x tm `(IsJust (integerToFin ~(P Bound n t) ~m))
171finFromIntegerErrors (CantUnify x tm `(IsJust (integerToFin ~n ~m)) err xs y)
184finFromIntegerErrors (CantUnify x tm `(IsJust (integerToFin ~n ~m)) err xs y)
172 = mkFinIntegerErr n m
185 = mkFinIntegerErr n m
173 [ TextPart "Could not show that" , TermPart n
186 [ TextPart "Could not show that" , TermPart n
174− , TextPart "is less than" , TermPart m
187+ , TextPart "is less than" , TermPart (getNat m)
176finFromIntegerErrors _ = Nothing
189finFromIntegerErrors _ = Nothing