-- ReadS type
, ReadS -- :: *; = String -> [(a,String)]
- -- utility functions
- , reads -- :: Read a => ReadS a
- , readp -- :: Read a => ReadP a
- , readEither -- :: Read a => String -> Either String a
- , read -- :: Read a => String -> a
-
-- H98 compatibility
, lex -- :: ReadS String
, lexLitChar -- :: ReadS String
-- Temporary
, readParen
+
+ -- XXX Can this be removed?
+ , readp
)
where
import Text.ParserCombinators.ReadPrec
import Data.Maybe
-import Data.Either
#ifndef __HADDOCK__
import {-# SOURCE #-} GHC.Unicode ( isDigit )
#endif
import GHC.Num
import GHC.Real
-import GHC.Float
+import GHC.Float ()
import GHC.Show
import GHC.Base
import GHC.Arr
readListPrecDefault = list readPrec
------------------------------------------------------------------------
--- utility functions
-
--- | equivalent to 'readsPrec' with a precedence of 0.
-reads :: Read a => ReadS a
-reads = readsPrec minPrec
-
-readp :: Read a => ReadP a
-readp = readPrec_to_P readPrec minPrec
-
-readEither :: Read a => String -> Either String a
-readEither s =
- case [ x | (x,"") <- readPrec_to_S read' minPrec s ] of
- [x] -> Right x
- [] -> Left "Prelude.read: no parse"
- _ -> Left "Prelude.read: ambiguous parse"
- where
- read' =
- do x <- readPrec
- lift P.skipSpaces
- return x
-
--- | The 'read' function reads input from a string, which must be
--- completely consumed by the input process.
-read :: Read a => String -> a
-read s = either error id (readEither s)
-
-------------------------------------------------------------------------
-- H98 compatibility
-- | The 'lex' function reads a single lexeme from the input, discarding
readListPrec = readListPrecDefault
readList = readListDefault
-instance (Read a, Read b) => Read (Either a b) where
- readPrec =
- parens
- ( prec appPrec
- ( do L.Ident "Left" <- lexP
- x <- step readPrec
- return (Left x)
- +++
- do L.Ident "Right" <- lexP
- y <- step readPrec
- return (Right y)
- )
- )
-
- readListPrec = readListPrecDefault
- readList = readListDefault
-
instance Read a => Read [a] where
readPrec = readListPrec
readListPrec = readListPrecDefault
instance (Ix a, Read a, Read b) => Read (Array a b) where
readPrec = parens $ prec appPrec $
do L.Ident "array" <- lexP
- bounds <- step readPrec
+ theBounds <- step readPrec
vals <- step readPrec
- return (array bounds vals)
+ return (array theBounds vals)
readListPrec = readListPrecDefault
readList = readListDefault
readListPrec = readListPrecDefault
readList = readListDefault
\end{code}
+
+\begin{code}
+-- XXX Can this be removed?
+
+readp :: Read a => ReadP a
+readp = readPrec_to_P readPrec minPrec
+\end{code}
+