on master help sign in
Rename truncate* to parse*FromScientific
commita14fb9f709076e9369ea741cf6b14ca85d027efb authorOleg Grenrus <oleg.grenrus@iki.fi> dateTue 5 Jul 2016, 16:27 (10 years ago) parent7e705d2
1 file changed+12−10
Data/Aeson/Types/FromJSON.hs+12−10
Data/Aeson/Types/FromJSON.hs+12−10
@@ -178,26 +178,28 @@ parseRealFloat _ Null = pure (0/0)
178178parseRealFloat expected v = typeMismatch expected v
179179{-# INLINE parseRealFloat #-}
180180
181−truncateIntegral :: forall a. Integral a => String -> Scientific -> Parser a
182−truncateIntegral expected s =
181+parseIntegralFromScientific :: forall a. Integral a => String -> Scientific -> Parser a
182+parseIntegralFromScientific expected s =
183183 case Scientific.floatingOrInteger s :: Either Double a of
184184 Right x -> pure x
185185 Left _ -> fail $ "Floating number specified for " ++ expected ++ ": " ++ show s
186−{-# INLINE truncateIntegral #-}
186+{-# INLINE parseIntegralFromScientific #-}
187187
188188parseIntegral :: Integral a => String -> Value -> Parser a
189−parseIntegral expected = withScientific expected $ truncateIntegral expected
189+parseIntegral expected =
190+ withScientific expected $ parseIntegralFromScientific expected
190191{-# INLINE parseIntegral #-}
191192
192−truncateBoundedIntegral :: (Bounded a, Integral a) => String -> Scientific -> Parser a
193−truncateBoundedIntegral expected s = maybe
193+parseBoundedIntegralFromScientific :: (Bounded a, Integral a) => String -> Scientific -> Parser a
194+parseBoundedIntegralFromScientific expected s = maybe
194195 (fail $ expected ++ " is either floating or will cause over or underflow: " ++ show s)
195196 pure
196197 (Scientific.toBoundedInteger s)
197−{-# INLINE truncateBoundedIntegral #-}
198+{-# INLINE parseBoundedIntegralFromScientific #-}
198199
199200parseBoundedIntegral :: (Bounded a, Integral a) => String -> Value -> Parser a
200−parseBoundedIntegral expected = withScientific expected $ truncateBoundedIntegral expected
201+parseBoundedIntegral expected =
202+ withScientific expected $ parseBoundedIntegralFromScientific expected
201203{-# INLINE parseBoundedIntegral #-}
202204
203205parseScientificText :: Text -> Parser Scientific
@@ -208,12 +210,12 @@ parseScientificText
208210
209211parseIntegralText :: Integral a => String -> Text -> Parser a
210212parseIntegralText expected t =
211− parseScientificText t >>= truncateIntegral expected
213+ parseScientificText t >>= parseIntegralFromScientific expected
212214{-# INLINE parseIntegralText #-}
213215
214216parseBoundedIntegralText :: (Bounded a, Integral a) => String -> Text -> Parser a
215217parseBoundedIntegralText expected t =
216− parseScientificText t >>= truncateBoundedIntegral expected
218+ parseScientificText t >>= parseBoundedIntegralFromScientific expected
217219
218220parseOptionalFieldWith :: (Value -> Parser (Maybe a))
219221 -> Object -> Text -> Parser (Maybe a)