diff --git a/Data/Text/Buildable.hs b/Data/Text/Buildable.hs index 4888eb4..72575aa 100644 --- a/Data/Text/Buildable.hs +++ b/Data/Text/Buildable.hs @@ -25,7 +25,7 @@ import Data.Int (Int8, Int16, Int32, Int64) import Data.Fixed (Fixed, HasResolution, showFixed) import Data.Ratio (Ratio, denominator, numerator) import Data.Text.Format.Functions ((<>)) -import Data.Text.Format.Int (decimal, hexadecimal) +import Data.Text.Format.Int (decimal, hexadecimal, integer) import Data.Text.Format.Types (Hex(..), Shown(..)) import Data.Text.Lazy.Builder import Data.Time.Calendar (Day, showGregorian) @@ -91,7 +91,7 @@ instance Buildable Int64 where {-# INLINE build #-} instance Buildable Integer where - build = decimal + build = integer 10 {-# INLINE build #-} instance (HasResolution a) => Buildable (Fixed a) where diff --git a/Data/Text/Format/Int.hs b/Data/Text/Format/Int.hs index 37858c9..a5e5430 100644 --- a/Data/Text/Format/Int.hs +++ b/Data/Text/Format/Int.hs @@ -12,6 +12,7 @@ module Data.Text.Format.Int ( decimal + , integer , hexadecimal , minus ) where @@ -39,7 +40,7 @@ import GHC.Integer.GMP.Internals # define PAIR(a,b) (a,b) #endif -decimal :: Integral a => a -> Builder +decimal :: (Bounded a, Integral a)=> a -> Builder {-# SPECIALIZE decimal :: Int -> Builder #-} {-# SPECIALIZE decimal :: Int8 -> Builder #-} {-# SPECIALIZE decimal :: Int16 -> Builder #-} @@ -52,6 +53,10 @@ decimal :: Integral a => a -> Builder {-# SPECIALIZE decimal :: Word64 -> Builder #-} {-# RULES "decimal/Integer" decimal = integer 10 :: Integer -> Builder #-} decimal i + | i == minBound = + -- special case, since (-i) would not be representable assuming two's + -- compliment: + minus <> integer 10 (negate $ fromIntegral i) | i < 0 = minus <> go (-i) | otherwise = go i where diff --git a/text-format.cabal b/text-format.cabal index 78bc4b5..79cbd16 100644 --- a/text-format.cabal +++ b/text-format.cabal @@ -1,5 +1,5 @@ name: text-format -version: 0.3.1.1 +version: 0.3.1.2 license: BSD3 license-file: LICENSE homepage: https://github.com/bos/text-format