@@ -1,6 +1,7 @@
11module Data.Fin
22
33%default total
4+%access public
45
56||| Numbers strictly less than some bound. The name comes from "finite sets".
67|||
@@ -143,19 +144,35 @@ fromInteger {n} x {prf} with (integerToFin x n)
143144 fromInteger {n} x {prf = ItIsJust} | Just y = y
144145
145146%language ErrorReflection
146−
147+total private
148+mkFinIntegerErr : TT -> TT -> List ErrorReportPart -> Maybe (List ErrorReportPart)
149+mkFinIntegerErr lit finSize subErr
150+ = Just [ TextPart "When using", TermPart lit
151+ , TextPart "as a literal for a"
152+ , TermPart `(Fin ~finSize)
153+ , SubReport subErr
154+ ]
147155total
148156finFromIntegerErrors : Err -> Maybe (List ErrorReportPart)
157+finFromIntegerErrors (CantUnify x tm `(IsJust (integerToFin ~(TConst c) ~m)) err xs y)
158+ = mkFinIntegerErr (TConst c) m
159+ [ TermPart (TConst c)
160+ , TextPart "is not strictly less than"
161+ , TermPart m
162+ ]
163+finFromIntegerErrors (CantUnify x tm `(IsJust (integerToFin ~(P Bound n t) ~m)) err xs y)
164+ = mkFinIntegerErr (P Bound n t) m
165+ [ TextPart "Could not show that", TermPart (P Bound n t)
166+ , TextPart "is less than", TermPart m
167+ , TextPart "because", TermPart (P Bound n t)
168+ , TextPart "is a bound variable instead of a constant"
169+ , TermPart (TConst (AType (ATInt ITBig)))
170+ ]
149171finFromIntegerErrors (CantUnify x tm `(IsJust (integerToFin ~n ~m)) err xs y)
150− = Just [ TextPart "When using", TermPart n
151− , TextPart "as a literal for a"
152− , TermPart `(Fin ~m)
153− , SubReport [ TextPart "Could not show that"
154− , TermPart n
155− , TextPart "is less than"
156− , TermPart m
157− ]
158− ]
172+ = mkFinIntegerErr n m
173+ [ TextPart "Could not show that" , TermPart n
174+ , TextPart "is less than" , TermPart m
175+ ]
159176finFromIntegerErrors _ = Nothing
160177
161178%error_handlers Data.Fin.fromInteger prf finFromIntegerErrors