[project @ 2002-06-06 16:03:16 by simonpj]
[ghc-base.git] / Numeric.hs
index 78af5b0..9f84fdb 100644 (file)
@@ -1,16 +1,14 @@
 {-# OPTIONS -fno-implicit-prelude #-}
 -----------------------------------------------------------------------------
--- 
+-- |
 -- Module      :  Numeric
 -- Copyright   :  (c) The University of Glasgow 2002
--- License     :  BSD-style (see the file libraries/core/LICENSE)
+-- License     :  BSD-style (see the file libraries/base/LICENSE)
 -- 
 -- Maintainer  :  libraries@haskell.org
 -- Stability   :  provisional
 -- Portability :  portable
 --
--- $Id: Numeric.hs,v 1.6 2002/04/11 12:03:43 simonpj Exp $
---
 -- Odds and ends, mostly functions for reading and showing
 -- RealFloat-like kind of values.
 --
@@ -64,11 +62,8 @@ import Array
 #endif
 
 
--- *********************************************************
--- *                                                      *
--- \subsection{Reading}
--- *                                                      *
--- *********************************************************
+-- -----------------------------------------------------------------------------
+-- Reading
 
 readInt :: Num a => a -> (Char -> Bool) -> (Char -> Int) -> ReadS a
 readInt base isDigit valDigit = readP_to_S (L.readIntP base isDigit valDigit)
@@ -83,10 +78,11 @@ readFloat = readP_to_S readFloatP
 
 readFloatP :: RealFrac a => ReadP a
 readFloatP =
-  do L.Number x <- L.lex
-     case L.numberToRational x of
-       Nothing -> pfail
-       Just y  -> return (fromRational y)
+  do tok <- L.lex
+     case tok of
+       L.Rat y  -> return (fromRational y)
+       L.Int i  -> return (fromInteger i)
+       other    -> pfail
 
 -- It's turgid to have readSigned work using list comprehensions,
 -- but it's specified as a ReadS to ReadS transformer
@@ -104,13 +100,8 @@ readSigned readPos = readParen False read'
                               return (n,s)
 
 
--- *********************************************************
--- *                                                      *
--- \subsection{Showing}
--- *                                                      *
--- *********************************************************
-
-
+-- -----------------------------------------------------------------------------
+-- Showing
 
 #ifdef __GLASGOW_HASKELL__
 showInt :: Integral a => a -> ShowS