ref: c48ae4afe7cbe79f6ac14a05c85bd7c84724c03d
parent: 937e72e41f8a3eb495b93db59a150fd42d872cee
author: Lennart Augustsson <lennart@augustsson.net>
date: Sat Sep 21 09:19:38 EDT 2024
Rearrange code so we can avoid Read.
--- a/lib/Data/Int/Instances.hs
+++ b/lib/Data/Int/Instances.hs
@@ -16,7 +16,7 @@
import Data.Ord
import Data.Ratio_Type
import Data.Real
-import Numeric
+import Numeric.Show
import Text.Show
--------------------------------------------------------------------------------
--- a/lib/Data/Integer.hs
+++ b/lib/Data/Integer.hs
@@ -27,7 +27,7 @@
import Data.Ord
import Data.Ratio_Type
import Data.Real
-import Numeric
+import Numeric.Show
import Text.Show
--
--- a/lib/Data/Word.hs
+++ b/lib/Data/Word.hs
@@ -19,7 +19,7 @@
import Data.Num
import Data.Ord
import Data.Real
-import Numeric
+import Numeric.Show
import Text.Show
instance Num Word where
--- a/lib/Foreign/Ptr.hs
+++ b/lib/Foreign/Ptr.hs
@@ -9,7 +9,7 @@
import Data.Eq
import Data.Function
import Data.Ord
-import Numeric(showHex)
+import Numeric.Show(showHex)
import Text.Show
instance forall a . Eq (Ptr a) where
--- a/lib/Numeric.hs
+++ b/lib/Numeric.hs
@@ -1,11 +1,5 @@
module Numeric(
- showSigned,
- showIntAtBase,
- showInt,
- showBin,
- showHex,
- showOct,
- showIntegral,
+ module Numeric.Show,
readSigned,
readInt,
@@ -16,63 +10,5 @@
readIntegral,
) where
import Prelude() -- do not import Prelude
-import Primitives
-import Control.Error
-import Data.Bool
-import Data.Char
-import Data.Eq
-import Data.Function
-import Data.Integral
-import Data.List
-import Data.Num
-import Data.Ord
-import Text.Read.Numeric
-import Text.Show(ShowS, showChar)
-
-showSigned :: forall a . (Ord a, Integral a) => (a -> ShowS) -> Int -> a -> ShowS
-showSigned showPos p n r
- | n < 0 =
- if p > (6::Int) then
- '(' : '-' : showPos (-n) (')' : r)
- else
- '-' : showPos (-n) r
- | otherwise = showPos n r
-
--- | Shows a /non-negative/ 'Integral' number using the base specified by the
--- first argument, and the character representation specified by the second.
--- If the argument, n, is <0 and -n == n (i.e., n == minBound) it will
--- return the string for (abs n).
-showIntAtBase :: forall a . (Ord a, Integral a) => a -> (Int -> Char) -> a -> ShowS
-showIntAtBase base toChr an
- | base <= 1 = error "Numeric.showIntAtBase: unsupported base"
- | an < 0 =
- if -an < 0 then
- -- We are at minBound
- showPos (- quot an base) . showPos (- rem an base)
- else
- error "Numeric.showIntAtBase: negative argument"
- | otherwise = showPos an
- where
- showPos n r =
- let
- c = toChr (fromIntegral (rem n base))
- in c `seq`
- if n < base then
- c : r
- else
- showPos (quot n base) (c : r)
-
-showInt :: forall a . (Ord a, Integral a) => a -> ShowS
-showInt = showIntAtBase 10 intToDigit
-
-showHex :: forall a . (Ord a, Integral a) => a -> ShowS
-showHex = showIntAtBase 16 intToDigit
-
-showOct :: forall a . (Ord a, Integral a) => a -> ShowS
-showOct = showIntAtBase 8 intToDigit
-
-showBin :: forall a . (Ord a, Integral a) => a -> ShowS
-showBin = showIntAtBase 2 intToDigit
-
-showIntegral :: forall a . (Ord a, Integral a) => Int -> a -> ShowS
-showIntegral = showSigned showInt
+import Numeric.Read
+import Numeric.Show
--- a/lib/Numeric/FormatFloat.hs
+++ b/lib/Numeric/FormatFloat.hs
@@ -10,7 +10,7 @@
) where
import Data.Char
-import Numeric
+import Numeric.Show
--showFloat :: (RealFloat a) => a -> ShowS
--showFloat x = showString (formatRealFloat FFGeneric Nothing x)
--- /dev/null
+++ b/lib/Numeric/Read.hs
@@ -1,0 +1,81 @@
+module Numeric.Read(
+ readParen,
+ --
+ readSigned,
+ readInt,
+ readBin,
+ readDec,
+ readOct,
+ readHex,
+ readIntegral,
+ readBoundedEnum,
+ ) where
+import Prelude() -- do not import Prelude
+import Primitives
+import Data.Bool
+import Data.Bounded
+import Data.Char
+import Data.Eq
+import Data.Enum
+import Data.Function
+import Data.Integral
+import Data.List
+import Data.Maybe_Type
+import Data.Num
+import Data.Ord
+import Data.String
+import Text.Read.OldLex(lex, dropSpace)
+import Text.Show
+
+type ReadS a = String -> [(a, String)]
+
+readParen :: forall a . Bool -> ReadS a -> ReadS a
+readParen b g = if b then mandatory else optional
+ where optional r = g r ++ mandatory r
+ mandatory r = [(x,u) | ("(",s) <- lex r,
+ (x,t) <- optional s,
+ (")",u) <- lex t ]
+
+--------------------------------------------------------
+
+readInt :: forall a . Num a => a -> (Char -> Bool) -> (Char -> Int) -> ReadS a
+readInt base isDig valDig cs@(c:_) | isDig c = loop 0 cs
+ where loop r (c:cs) | isDig c = loop (r * base + fromIntegral (valDig c)) cs
+ loop r ds = [(r, ds)]
+readInt _ _ _ _ = []
+
+readBin :: forall a . (Num a) => ReadS a
+readBin = readInt 2 isBinDigit digitToInt
+
+isBinDigit :: Char -> Bool
+isBinDigit c = c == '0' || c == '1'
+
+readOct :: forall a . (Num a) => ReadS a
+readOct = readInt 8 isOctDigit digitToInt
+
+readDec :: forall a . (Num a) => ReadS a
+readDec = readInt 10 isDigit digitToInt
+
+readHex :: forall a . (Num a) => ReadS a
+readHex = readInt 16 isHexDigit digitToInt
+
+readSigned :: forall a . (Num a) => ReadS a -> ReadS a
+readSigned readPos = readParen False read'
+ where
+ read' :: ReadS a
+ read' r = readPos r ++
+ [ (- x, t) | ("-", s) <- lex r, (x, t) <- readPos s ]
+
+readIntegral :: forall a . (Integral a) => Int -> ReadS a
+readIntegral _ = readSigned (readAny . dropSpace)
+ where readAny ('0':'x':cs) = readHex cs
+ readAny ('0':'X':cs) = readHex cs
+ readAny ('0':'o':cs) = readOct cs
+ readAny ('0':'O':cs) = readOct cs
+ readAny ('0':'b':cs) = readBin cs
+ readAny ('0':'B':cs) = readBin cs
+ readAny cs = readDec cs
+
+readBoundedEnum :: forall a . (Enum a, Bounded a, Show a) => ReadS a
+readBoundedEnum = \ r -> [ (e, t) | (s, t) <- lex r, Just e <- [lookup s table] ]
+ where table = [ (show e, e) | e <- [ minBound .. maxBound ] ]
--- /dev/null
+++ b/lib/Numeric/Show.hs
@@ -1,0 +1,69 @@
+module Numeric.Show(
+ showSigned,
+ showIntAtBase,
+ showInt,
+ showBin,
+ showHex,
+ showOct,
+ showIntegral,
+ ) where
+import Prelude() -- do not import Prelude
+import Primitives
+import Control.Error
+import Data.Bool
+import Data.Char
+import Data.Eq
+import Data.Function
+import Data.Integral
+import Data.List
+import Data.Num
+import Data.Ord
+import Text.Show(ShowS, showChar)
+
+showSigned :: forall a . (Ord a, Integral a) => (a -> ShowS) -> Int -> a -> ShowS
+showSigned showPos p n r
+ | n < 0 =
+ if p > (6::Int) then
+ '(' : '-' : showPos (-n) (')' : r)
+ else
+ '-' : showPos (-n) r
+ | otherwise = showPos n r
+
+-- | Shows a /non-negative/ 'Integral' number using the base specified by the
+-- first argument, and the character representation specified by the second.
+-- If the argument, n, is <0 and -n == n (i.e., n == minBound) it will
+-- return the string for (abs n).
+showIntAtBase :: forall a . (Ord a, Integral a) => a -> (Int -> Char) -> a -> ShowS
+showIntAtBase base toChr an
+ | base <= 1 = error "Numeric.showIntAtBase: unsupported base"
+ | an < 0 =
+ if -an < 0 then
+ -- We are at minBound
+ showPos (- quot an base) . showPos (- rem an base)
+ else
+ error "Numeric.showIntAtBase: negative argument"
+ | otherwise = showPos an
+ where
+ showPos n r =
+ let
+ c = toChr (fromIntegral (rem n base))
+ in c `seq`
+ if n < base then
+ c : r
+ else
+ showPos (quot n base) (c : r)
+
+showInt :: forall a . (Ord a, Integral a) => a -> ShowS
+showInt = showIntAtBase 10 intToDigit
+
+showHex :: forall a . (Ord a, Integral a) => a -> ShowS
+showHex = showIntAtBase 16 intToDigit
+
+showOct :: forall a . (Ord a, Integral a) => a -> ShowS
+showOct = showIntAtBase 8 intToDigit
+
+showBin :: forall a . (Ord a, Integral a) => a -> ShowS
+showBin = showIntAtBase 2 intToDigit
+
+showIntegral :: forall a . (Ord a, Integral a) => Int -> a -> ShowS
+showIntegral = showSigned showInt
--- a/lib/Text/Printf.hs
+++ b/lib/Text/Printf.hs
@@ -96,7 +96,7 @@
import Data.Int
import Data.List (stripPrefix)
import Data.Word
-import Numeric
+import Numeric.Show
import Numeric.FormatFloat(showEFloat, showFFloat, showGFloat, showFFloatAlt, showGFloatAlt)
import Numeric.Natural
import System.IO
--- a/lib/Text/Read/Numeric.hs
+++ /dev/null
@@ -1,81 +1,0 @@
-module Text.Read.Numeric(
- readParen,
- --
- readSigned,
- readInt,
- readBin,
- readDec,
- readOct,
- readHex,
- readIntegral,
- readBoundedEnum,
- ) where
-import Prelude() -- do not import Prelude
-import Primitives
-import Data.Bool
-import Data.Bounded
-import Data.Char
-import Data.Eq
-import Data.Enum
-import Data.Function
-import Data.Integral
-import Data.List
-import Data.Maybe_Type
-import Data.Num
-import Data.Ord
-import Data.String
-import Text.Read.OldLex(lex, dropSpace)
-import Text.Show
-
-type ReadS a = String -> [(a, String)]
-
-readParen :: forall a . Bool -> ReadS a -> ReadS a
-readParen b g = if b then mandatory else optional
- where optional r = g r ++ mandatory r
- mandatory r = [(x,u) | ("(",s) <- lex r,
- (x,t) <- optional s,
- (")",u) <- lex t ]
-
---------------------------------------------------------
-
-readInt :: forall a . Num a => a -> (Char -> Bool) -> (Char -> Int) -> ReadS a
-readInt base isDig valDig cs@(c:_) | isDig c = loop 0 cs
- where loop r (c:cs) | isDig c = loop (r * base + fromIntegral (valDig c)) cs
- loop r ds = [(r, ds)]
-readInt _ _ _ _ = []
-
-readBin :: forall a . (Num a) => ReadS a
-readBin = readInt 2 isBinDigit digitToInt
-
-isBinDigit :: Char -> Bool
-isBinDigit c = c == '0' || c == '1'
-
-readOct :: forall a . (Num a) => ReadS a
-readOct = readInt 8 isOctDigit digitToInt
-
-readDec :: forall a . (Num a) => ReadS a
-readDec = readInt 10 isDigit digitToInt
-
-readHex :: forall a . (Num a) => ReadS a
-readHex = readInt 16 isHexDigit digitToInt
-
-readSigned :: forall a . (Num a) => ReadS a -> ReadS a
-readSigned readPos = readParen False read'
- where
- read' :: ReadS a
- read' r = readPos r ++
- [ (- x, t) | ("-", s) <- lex r, (x, t) <- readPos s ]
-
-readIntegral :: forall a . (Integral a) => Int -> ReadS a
-readIntegral _ = readSigned (readAny . dropSpace)
- where readAny ('0':'x':cs) = readHex cs
- readAny ('0':'X':cs) = readHex cs
- readAny ('0':'o':cs) = readOct cs
- readAny ('0':'O':cs) = readOct cs
- readAny ('0':'b':cs) = readBin cs
- readAny ('0':'B':cs) = readBin cs
- readAny cs = readDec cs
-
-readBoundedEnum :: forall a . (Enum a, Bounded a, Show a) => ReadS a
-readBoundedEnum = \ r -> [ (e, t) | (s, t) <- lex r, Just e <- [lookup s table] ]
- where table = [ (show e, e) | e <- [ minBound .. maxBound ] ]
--- a/paths/Paths_MicroHs.hs
+++ b/paths/Paths_MicroHs.hs
@@ -3,7 +3,7 @@
version,
getDataDir,
) where
-import Prelude(); import MiniPrelude
+import Prelude(); import MHSPrelude
import Data.Version
getDataDir :: IO FilePath
--
⑨