@@ -189,18 +189,14 @@ parseIntegral :: Integral a => String -> Value -> Parser a
189189parseIntegral expected = withScientific expected $ truncateIntegral expected
190190{-# INLINE parseIntegral #-}
191191
192−truncateBoundedIntegral :: Integral a => String -> Scientific -> Parser a
193−truncateBoundedIntegral expected s
194− | Scientific.isInteger s =
195− let x = truncate s
196− in if fromIntegral x == s
197− then pure x
198− else fail $ "Truncating to " ++ expected ++ " cause over or underflow: " ++ show s
199− | otherwise =
200− fail $ "Floating number specified for " ++ expected ++ ": " ++ show s
192+truncateBoundedIntegral :: (Bounded a, Integral a) => String -> Scientific -> Parser a
193+truncateBoundedIntegral expected s = maybe
194+ (fail $ expected ++ " is either floating or will cause over or underflow: " ++ show s)
195+ pure
196+ (Scientific.toBoundedInteger s)
201197{-# INLINE truncateBoundedIntegral #-}
202198
203−parseBoundedIntegral :: Integral a => String -> Value -> Parser a
199+parseBoundedIntegral :: (Bounded a, Integral a) => String -> Value -> Parser a
204200parseBoundedIntegral expected = withScientific expected $ truncateBoundedIntegral expected
205201{-# INLINE parseBoundedIntegral #-}
206202
@@ -215,7 +211,7 @@ parseIntegralText expected t =
215211 parseScientificText t >>= truncateIntegral expected
216212{-# INLINE parseIntegralText #-}
217213
218−parseBoundedIntegralText :: Integral a => String -> Text -> Parser a
214+parseBoundedIntegralText :: (Bounded a, Integral a) => String -> Text -> Parser a
219215parseBoundedIntegralText expected t =
220216 parseScientificText t >>= truncateBoundedIntegral expected
221217