on master help sign in
Merge pull request #162 from basvandijk/master
20b8432Bryan O'Sullivan
Data/Aeson/Types/Instances.hs+7−6
@@ -55,7 +55,8 @@ import Control.Applicative ((<$>), (<*>), (<|>), pure, empty)
55import Data.Aeson.Functions
55import Data.Aeson.Functions
56import Data.Aeson.Types.Class
56import Data.Aeson.Types.Class
57import Data.Aeson.Types.Internal
57import Data.Aeson.Types.Internal
58−import Data.Scientific (Scientific, coefficient, base10Exponent)
58+import Data.Scientific (Scientific)
59+import qualified Data.Scientific as Scientific (coefficient, base10Exponent, fromFloatDigits)
59import Data.Attoparsec.Number (Number(..))
60import Data.Attoparsec.Number (Number(..))
60import Data.Fixed
61import Data.Fixed
61import Data.Hashable (Hashable(..))
62import Data.Hashable (Hashable(..))
@@ -166,7 +167,7 @@ instance ToJSON Double where
166realFloatToJSON :: RealFloat a => a -> Value
167realFloatToJSON :: RealFloat a => a -> Value
167realFloatToJSON d
168realFloatToJSON d
168 | isNaN d || isInfinite d = Null
169 | isNaN d || isInfinite d = Null
169− | otherwise = Number $ realToFrac d
170+ | otherwise = Number $ Scientific.fromFloatDigits d
170{-# INLINE realFloatToJSON #-}
171{-# INLINE realFloatToJSON #-}
171
172
172instance FromJSON Double where
173instance FromJSON Double where
@@ -177,7 +178,7 @@ instance FromJSON Double where
177
178
178instance ToJSON Number where
179instance ToJSON Number where
179 toJSON (D d) = toJSON d
180 toJSON (D d) = toJSON d
180− toJSON (I i) = Number $ fromInteger i
181+ toJSON (I i) = toJSON i
181 {-# INLINE toJSON #-}
182 {-# INLINE toJSON #-}
182
183
183instance FromJSON Number where
184instance FromJSON Number where
@@ -229,7 +230,7 @@ parseIntegral = withScientific "Integral" $ pure . floor
229{-# INLINE parseIntegral #-}
230{-# INLINE parseIntegral #-}
230
231
231instance ToJSON Integer where
232instance ToJSON Integer where
232− toJSON = Number . fromIntegral
233+ toJSON = Number . fromInteger
233 {-# INLINE toJSON #-}
234 {-# INLINE toJSON #-}
234
235
235instance FromJSON Integer where
236instance FromJSON Integer where
@@ -788,6 +789,6 @@ scientificToNumber s
788 | e < 0 = D $ fromInteger c / 10 ^ negate e
789 | e < 0 = D $ fromInteger c / 10 ^ negate e
789 | otherwise = I $ c * 10 ^ e
790 | otherwise = I $ c * 10 ^ e
790 where
791 where
791− e = base10Exponent s
792+ e = Scientific.base10Exponent s
792− c = coefficient s
793+ c = Scientific.coefficient s
793{-# INLINE scientificToNumber #-}
794{-# INLINE scientificToNumber #-}