[project @ 2001-10-18 08:03:29 by simonpj]
[ghc-hetmet.git] / ghc / lib / std / PrelRead.lhs
index 995b9e6..b91cb96 100644 (file)
@@ -1,5 +1,5 @@
 % ------------------------------------------------------------------------------
-% $Id: PrelRead.lhs,v 1.18 2001/02/28 00:01:03 qrczak Exp $
+% $Id: PrelRead.lhs,v 1.21 2001/08/28 09:55:35 simonmar Exp $
 %
 % (c) The University of Glasgow, 1994-2000
 %
@@ -13,7 +13,7 @@ Instances of the Read class.
 
 module PrelRead where
 
-import PrelErr         ( error )
+import {-# SOURCE #-} PrelErr          ( error )
 import PrelEnum                ( Enum(..), maxBound )
 import PrelNum
 import PrelReal
@@ -22,10 +22,6 @@ import PrelList
 import PrelMaybe
 import PrelShow                -- isAlpha etc
 import PrelBase
-
--- needed for readIO and instance Read Buffermode
-import PrelIOBase ( IO, userError, BufferMode(..) )
-import PrelException ( ioError )
 \end{code}
 
 %*********************************************************
@@ -101,19 +97,6 @@ read s          =
     (x,str1) <- reads str
     ("","")  <- lex str1
     return x
-
-  -- raises an exception instead of an error
-readIO          :: Read a => String -> IO a
-readIO s        =  case (do { (x,t) <- reads s ; ("","") <- lex t ; return x }) of
-#ifndef NEW_READS_REP
-                       [x]    -> return x
-                       []     -> ioError (userError "Prelude.readIO: no parse")
-                       _      -> ioError (userError "Prelude.readIO: ambiguous parse")
-#else
-                        Just x -> return x
-                        Nothing  -> ioError (userError "Prelude.readIO: no parse")
-#endif
-
 \end{code}
 
 \begin{code}
@@ -569,23 +552,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
@@ -623,26 +605,3 @@ readRational__ top_s
 #endif
 
 \end{code}
-
-%*********************************************************
-%*                                                     *
-\subsection{Reading BufferMode}
-%*                                                     *
-%*********************************************************
-
-This instance decl is here rather than somewhere more appropriate in
-order that we can avoid both orphan-instance modules and recursive
-dependencies.
-
-\begin{code}
-instance Read BufferMode where
-    readsPrec _ = 
-      readParen False
-       (\r ->  let lr = lex r
-               in
-               [(NoBuffering, rest)       | ("NoBuffering", rest) <- lr] ++
-               [(LineBuffering,rest)      | ("LineBuffering",rest) <- lr] ++
-               [(BlockBuffering mb,rest2) | ("BlockBuffering",rest1) <- lr,
-                                            (mb, rest2) <- reads rest1])
-
-\end{code}