X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=Numeric.hs;h=4b202d0efd67d0705eceaaba1f45dde6eeb5caf6;hb=7dbb606d7b57cdad87a0ffbdb6ea4a274ebca7c0;hp=4868a8de68877d1b5e687d0bc90b572c3f9beaba;hpb=bf705fb9aeb5c1ef01a8d806374389a703fbb25f;p=ghc-base.git diff --git a/Numeric.hs b/Numeric.hs index 4868a8d..4b202d0 100644 --- a/Numeric.hs +++ b/Numeric.hs @@ -1,4 +1,5 @@ -{-# OPTIONS_GHC -fno-implicit-prelude #-} +{-# LANGUAGE CPP, NoImplicitPrelude, MagicHash #-} + ----------------------------------------------------------------------------- -- | -- Module : Numeric @@ -47,7 +48,7 @@ module Numeric ( readHex, -- :: (Integral a) => ReadS a readFloat, -- :: (RealFloat a) => ReadS a - + lexDigits, -- :: ReadS String -- * Miscellaneous @@ -111,7 +112,7 @@ readFloatP = case tok of L.Rat y -> return (fromRational y) L.Int i -> return (fromInteger i) - other -> pfail + _ -> pfail -- It's turgid to have readSigned work using list comprehensions, -- but it's specified as a ReadS to ReadS transformer @@ -135,9 +136,9 @@ readSigned readPos = readParen False read' -- | Show /non-negative/ 'Integral' numbers in base 10. showInt :: Integral a => a -> ShowS -showInt n cs - | n < 0 = error "Numeric.showInt: can't show negative numbers" - | otherwise = go n cs +showInt n0 cs0 + | n0 < 0 = error "Numeric.showInt: can't show negative numbers" + | otherwise = go n0 cs0 where go n cs | n < 10 = case unsafeChr (ord '0' + fromIntegral n) of @@ -197,17 +198,17 @@ showGFloat d x = showString (formatRealFloat FFGeneric d x) -- | Shows a /non-negative/ 'Integral' number using the base specified by the -- first argument, and the character representation specified by the second. showIntAtBase :: Integral a => a -> (Int -> Char) -> a -> ShowS -showIntAtBase base toChr n r +showIntAtBase base toChr n0 r0 | base <= 1 = error ("Numeric.showIntAtBase: applied to unsupported base " ++ show base) - | n < 0 = error ("Numeric.showIntAtBase: applied to negative number " ++ show n) - | otherwise = showIt (quotRem n base) r + | n0 < 0 = error ("Numeric.showIntAtBase: applied to negative number " ++ show n0) + | otherwise = showIt (quotRem n0 base) r0 where showIt (n,d) r = seq c $ -- stricter than necessary case n of 0 -> r' _ -> showIt (quotRem n base) r' where - c = toChr (fromIntegral d) + c = toChr (fromIntegral d) r' = c : r -- | Show /non-negative/ 'Integral' numbers in base 16.