% ------------------------------------------------------------------------------
-% $Id: PrelRead.lhs,v 1.19 2001/05/22 19:25:49 qrczak Exp $
+% $Id: PrelRead.lhs,v 1.22 2001/11/23 16:20:08 simonpj Exp $
%
% (c) The University of Glasgow, 1994-2000
%
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}
%*********************************************************
(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
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