From 863567264b7fb21f152a4c3b7ab904221be44d07 Mon Sep 17 00:00:00 2001 From: Li-yao Xia Date: Fri, 10 Jul 2026 09:54:35 +0200 Subject: [PATCH] Relax constraints on decimal, hexadecimal, hex from Integral to Num --- src/Data/Text/Lazy/Read.hs | 8 ++++---- src/Data/Text/Read.hs | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/Data/Text/Lazy/Read.hs b/src/Data/Text/Lazy/Read.hs index 9757d278..65489b0a 100644 --- a/src/Data/Text/Lazy/Read.hs +++ b/src/Data/Text/Lazy/Read.hs @@ -54,7 +54,7 @@ type Parser = IParser Text -- attempt to detect overflow, so a sufficiently long input may give -- incorrect results. If you are worried about overflow, use -- 'Integer' for your result type. -decimal :: Integral a => Reader a +decimal :: Num a => Reader a {-# SPECIALIZE decimal :: Reader Int #-} {-# SPECIALIZE decimal :: Reader Int8 #-} {-# SPECIALIZE decimal :: Reader Int16 #-} @@ -83,7 +83,7 @@ decimal txt -- attempt to detect overflow, so a sufficiently long input may give -- incorrect results. If you are worried about overflow, use -- 'Integer' for your result type. -hexadecimal :: Integral a => Reader a +hexadecimal :: Num a => Reader a {-# SPECIALIZE hexadecimal :: Reader Int #-} {-# SPECIALIZE hexadecimal :: Reader Integer #-} hexadecimal txt @@ -91,7 +91,7 @@ hexadecimal txt | otherwise = hex txt where (h,t) = T.splitAt 2 txt -hex :: Integral a => Reader a +hex :: Num a => Reader a {-# SPECIALIZE hexadecimal :: Reader Int #-} {-# SPECIALIZE hexadecimal :: Reader Int8 #-} {-# SPECIALIZE hexadecimal :: Reader Int16 #-} @@ -114,7 +114,7 @@ hex txt -- which will be either 'hexDigitToInt' (hexadecimal) or 'digitToInt' (decimal only). -- It may be arbitrarily long. {-# INLINE integer #-} -integer :: Integral a => Base -> (Char -> Word) -> Text -> a +integer :: Num a => Base -> (Char -> Word) -> Text -> a integer (Base { base, maxWord, maxDigits }) digit t0 | n0 <= maxDigits' = fromIntegral (word base digit t0) | otherwise = scanWords [word' t01] (n0 - mswSize) t02 diff --git a/src/Data/Text/Read.hs b/src/Data/Text/Read.hs index c4c6dae4..d0581b79 100644 --- a/src/Data/Text/Read.hs +++ b/src/Data/Text/Read.hs @@ -49,7 +49,7 @@ type Parser a = IParser Text a -- attempt to detect overflow, so a sufficiently long input may give -- incorrect results. If you are worried about overflow, use -- 'Integer' for your result type. -decimal :: Integral a => Reader a +decimal :: Num a => Reader a {-# SPECIALIZE decimal :: Reader Int #-} {-# SPECIALIZE decimal :: Reader Int8 #-} {-# SPECIALIZE decimal :: Reader Int16 #-} @@ -78,7 +78,7 @@ decimal txt -- attempt to detect overflow, so a sufficiently long input may give -- incorrect results. If you are worried about overflow, use -- 'Integer' for your result type. -hexadecimal :: Integral a => Reader a +hexadecimal :: Num a => Reader a {-# SPECIALIZE hexadecimal :: Reader Int #-} {-# SPECIALIZE hexadecimal :: Reader Int8 #-} {-# SPECIALIZE hexadecimal :: Reader Int16 #-} @@ -95,7 +95,7 @@ hexadecimal txt | otherwise = hex txt where (h,t) = T.splitAt 2 txt -hex :: Integral a => Reader a +hex :: Num a => Reader a {-# SPECIALIZE hex :: Reader Int #-} {-# SPECIALIZE hex :: Reader Int8 #-} {-# SPECIALIZE hex :: Reader Int16 #-} @@ -117,7 +117,7 @@ hex txt -- The input text must only contain ASCII digits, to be read by the @Char -> Word@ function -- which will be either 'hexDigitToInt' (hexadecimal) or 'digitToInt' (decimal only). -- It may be arbitrarily long. -integer :: Integral a => Base -> (Char -> Word) -> Text -> a +integer :: Num a => Base -> (Char -> Word) -> Text -> a integer (Base { base, maxWord, maxDigits }) digit t0 | TU.lengthWord8 t0 <= maxDigits = fromIntegral (word base digit t0) | otherwise = scanWords [word' (TU.takeWord8 mswSize t0)] (TU.dropWord8 mswSize t0)