[project @ 2002-02-13 12:12:08 by simonmar]
[ghc-base.git] / GHC / Read.lhs
index 1e66f85..a01c8e2 100644 (file)
@@ -1,5 +1,5 @@
 % ------------------------------------------------------------------------------
-% $Id: Read.lhs,v 1.1 2001/06/28 14:15:03 simonmar Exp $
+% $Id: Read.lhs,v 1.3 2001/12/21 15:07:25 simonmar Exp $
 %
 % (c) The University of Glasgow, 1994-2000
 %
@@ -13,13 +13,15 @@ Instances of the Read class.
 
 module GHC.Read where
 
+import Data.Maybe
+import Data.Either
+
 import {-# SOURCE #-} GHC.Err          ( error )
 import GHC.Enum                ( Enum(..), maxBound )
 import GHC.Num
 import GHC.Real
 import GHC.Float
 import GHC.List
-import GHC.Maybe
 import GHC.Show                -- isAlpha etc
 import GHC.Base
 \end{code}
@@ -371,7 +373,7 @@ instance  (Integral a, Read a)  => Read (Ratio a)  where
                                (x,s)   <- reads r
                                ("%",t) <- lex s
                                (y,u)   <- reads t
-                               return (x%y,u))
+                               return (x % y,u))
 
 instance  (Read a) => Read [a]  where
     readsPrec _         = readList
@@ -552,23 +554,22 @@ point type to obtain the same results.
                    ReadS Double,
                    ReadS Float     #-} 
 readFloat :: (RealFloat a) => ReadS a
-readFloat r = do
-    (x,t) <- readRational r
-    return (fromRational x,t)
-
-readRational :: ReadS Rational -- NB: doesn't handle leading "-"
-
-readRational r =
-   (do 
-      (n,d,s) <- readFix r
-      (k,t)   <- readExp s
-      return ((n%1)*10^^(k-d), t )) ++
+readFloat r =
+   (do
+      (x,t) <- readRational r
+      return (fromRational x,t) ) ++
    (do
       ("NaN",t) <- lex r
       return (0/0,t) ) ++
    (do
       ("Infinity",t) <- lex r
       return (1/0,t) )
+
+readRational :: ReadS Rational -- NB: doesn't handle leading "-"
+readRational r = do 
+     (n,d,s) <- readFix r
+     (k,t)   <- readExp s
+     return ((n%1)*10^^(k-d), t)
  where
      readFix r = do
        (ds,s)  <- lexDecDigits r