hGetContents: close the handle properly on error
[ghc-base.git] / GHC / Read.lhs
1 \begin{code}
2 {-# OPTIONS_GHC -XNoImplicitPrelude #-}
3 {-# OPTIONS_HADDOCK hide #-}
4 -----------------------------------------------------------------------------
5 -- |
6 -- Module      :  GHC.Read
7 -- Copyright   :  (c) The University of Glasgow, 1994-2002
8 -- License     :  see libraries/base/LICENSE
9 -- 
10 -- Maintainer  :  cvs-ghc@haskell.org
11 -- Stability   :  internal
12 -- Portability :  non-portable (GHC Extensions)
13 --
14 -- The 'Read' class and instances for basic data types.
15 --
16 -----------------------------------------------------------------------------
17
18 -- #hide
19 module GHC.Read
20   ( Read(..)   -- class
21
22   -- ReadS type
23   , ReadS      -- :: *; = String -> [(a,String)]
24
25   -- H98 compatibility
26   , lex         -- :: ReadS String
27   , lexLitChar  -- :: ReadS String
28   , readLitChar -- :: ReadS Char
29   , lexDigits   -- :: ReadS String
30
31   -- defining readers
32   , lexP       -- :: ReadPrec Lexeme
33   , paren      -- :: ReadPrec a -> ReadPrec a
34   , parens     -- :: ReadPrec a -> ReadPrec a
35   , list       -- :: ReadPrec a -> ReadPrec [a]
36   , choose     -- :: [(String, ReadPrec a)] -> ReadPrec a
37   , readListDefault, readListPrecDefault
38
39   -- Temporary
40   , readParen
41
42   -- XXX Can this be removed?
43   , readp
44   )
45  where
46
47 import qualified Text.ParserCombinators.ReadP as P
48
49 import Text.ParserCombinators.ReadP
50   ( ReadP
51   , ReadS
52   , readP_to_S
53   )
54
55 import qualified Text.Read.Lex as L
56 -- Lex exports 'lex', which is also defined here,
57 -- hence the qualified import.
58 -- We can't import *anything* unqualified, because that
59 -- confuses Haddock.
60
61 import Text.ParserCombinators.ReadPrec
62
63 import Data.Maybe
64
65 #ifndef __HADDOCK__
66 import {-# SOURCE #-} GHC.Unicode       ( isDigit )
67 #endif
68 import GHC.Num
69 import GHC.Real
70 import GHC.Float ()
71 import GHC.Show
72 import GHC.Base
73 import GHC.Arr
74 \end{code}
75
76
77 \begin{code}
78 -- | @'readParen' 'True' p@ parses what @p@ parses, but surrounded with
79 -- parentheses.
80 --
81 -- @'readParen' 'False' p@ parses what @p@ parses, but optionally
82 -- surrounded with parentheses.
83 readParen       :: Bool -> ReadS a -> ReadS a
84 -- A Haskell 98 function
85 readParen b g   =  if b then mandatory else optional
86                    where optional r  = g r ++ mandatory r
87                          mandatory r = do
88                                 ("(",s) <- lex r
89                                 (x,t)   <- optional s
90                                 (")",u) <- lex t
91                                 return (x,u)
92 \end{code}
93
94
95 %*********************************************************
96 %*                                                      *
97 \subsection{The @Read@ class}
98 %*                                                      *
99 %*********************************************************
100
101 \begin{code}
102 ------------------------------------------------------------------------
103 -- class Read
104
105 -- | Parsing of 'String's, producing values.
106 --
107 -- Minimal complete definition: 'readsPrec' (or, for GHC only, 'readPrec')
108 --
109 -- Derived instances of 'Read' make the following assumptions, which
110 -- derived instances of 'Text.Show.Show' obey:
111 --
112 -- * If the constructor is defined to be an infix operator, then the
113 --   derived 'Read' instance will parse only infix applications of
114 --   the constructor (not the prefix form).
115 --
116 -- * Associativity is not used to reduce the occurrence of parentheses,
117 --   although precedence may be.
118 --
119 -- * If the constructor is defined using record syntax, the derived 'Read'
120 --   will parse only the record-syntax form, and furthermore, the fields
121 --   must be given in the same order as the original declaration.
122 --
123 -- * The derived 'Read' instance allows arbitrary Haskell whitespace
124 --   between tokens of the input string.  Extra parentheses are also
125 --   allowed.
126 --
127 -- For example, given the declarations
128 --
129 -- > infixr 5 :^:
130 -- > data Tree a =  Leaf a  |  Tree a :^: Tree a
131 --
132 -- the derived instance of 'Read' in Haskell 98 is equivalent to
133 --
134 -- > instance (Read a) => Read (Tree a) where
135 -- >
136 -- >         readsPrec d r =  readParen (d > app_prec)
137 -- >                          (\r -> [(Leaf m,t) |
138 -- >                                  ("Leaf",s) <- lex r,
139 -- >                                  (m,t) <- readsPrec (app_prec+1) s]) r
140 -- >
141 -- >                       ++ readParen (d > up_prec)
142 -- >                          (\r -> [(u:^:v,w) |
143 -- >                                  (u,s) <- readsPrec (up_prec+1) r,
144 -- >                                  (":^:",t) <- lex s,
145 -- >                                  (v,w) <- readsPrec (up_prec+1) t]) r
146 -- >
147 -- >           where app_prec = 10
148 -- >                 up_prec = 5
149 --
150 -- Note that right-associativity of @:^:@ is unused.
151 --
152 -- The derived instance in GHC is equivalent to
153 --
154 -- > instance (Read a) => Read (Tree a) where
155 -- >
156 -- >         readPrec = parens $ (prec app_prec $ do
157 -- >                                  Ident "Leaf" <- lexP
158 -- >                                  m <- step readPrec
159 -- >                                  return (Leaf m))
160 -- >
161 -- >                      +++ (prec up_prec $ do
162 -- >                                  u <- step readPrec
163 -- >                                  Symbol ":^:" <- lexP
164 -- >                                  v <- step readPrec
165 -- >                                  return (u :^: v))
166 -- >
167 -- >           where app_prec = 10
168 -- >                 up_prec = 5
169 -- >
170 -- >         readListPrec = readListPrecDefault
171
172 class Read a where
173   -- | attempts to parse a value from the front of the string, returning
174   -- a list of (parsed value, remaining string) pairs.  If there is no
175   -- successful parse, the returned list is empty.
176   --
177   -- Derived instances of 'Read' and 'Text.Show.Show' satisfy the following:
178   --
179   -- * @(x,\"\")@ is an element of
180   --   @('readsPrec' d ('Text.Show.showsPrec' d x \"\"))@.
181   --
182   -- That is, 'readsPrec' parses the string produced by
183   -- 'Text.Show.showsPrec', and delivers the value that
184   -- 'Text.Show.showsPrec' started with.
185
186   readsPrec    :: Int   -- ^ the operator precedence of the enclosing
187                         -- context (a number from @0@ to @11@).
188                         -- Function application has precedence @10@.
189                 -> ReadS a
190
191   -- | The method 'readList' is provided to allow the programmer to
192   -- give a specialised way of parsing lists of values.
193   -- For example, this is used by the predefined 'Read' instance of
194   -- the 'Char' type, where values of type 'String' should be are
195   -- expected to use double quotes, rather than square brackets.
196   readList     :: ReadS [a]
197
198   -- | Proposed replacement for 'readsPrec' using new-style parsers (GHC only).
199   readPrec     :: ReadPrec a
200
201   -- | Proposed replacement for 'readList' using new-style parsers (GHC only).
202   -- The default definition uses 'readList'.  Instances that define 'readPrec'
203   -- should also define 'readListPrec' as 'readListPrecDefault'.
204   readListPrec :: ReadPrec [a]
205   
206   -- default definitions
207   readsPrec    = readPrec_to_S readPrec
208   readList     = readPrec_to_S (list readPrec) 0
209   readPrec     = readS_to_Prec readsPrec
210   readListPrec = readS_to_Prec (\_ -> readList)
211
212 readListDefault :: Read a => ReadS [a]
213 -- ^ A possible replacement definition for the 'readList' method (GHC only).
214 --   This is only needed for GHC, and even then only for 'Read' instances
215 --   where 'readListPrec' isn't defined as 'readListPrecDefault'.
216 readListDefault = readPrec_to_S readListPrec 0
217
218 readListPrecDefault :: Read a => ReadPrec [a]
219 -- ^ A possible replacement definition for the 'readListPrec' method,
220 --   defined using 'readPrec' (GHC only).
221 readListPrecDefault = list readPrec
222
223 ------------------------------------------------------------------------
224 -- H98 compatibility
225
226 -- | The 'lex' function reads a single lexeme from the input, discarding
227 -- initial white space, and returning the characters that constitute the
228 -- lexeme.  If the input string contains only white space, 'lex' returns a
229 -- single successful \`lexeme\' consisting of the empty string.  (Thus
230 -- @'lex' \"\" = [(\"\",\"\")]@.)  If there is no legal lexeme at the
231 -- beginning of the input string, 'lex' fails (i.e. returns @[]@).
232 --
233 -- This lexer is not completely faithful to the Haskell lexical syntax
234 -- in the following respects:
235 --
236 -- * Qualified names are not handled properly
237 --
238 -- * Octal and hexadecimal numerics are not recognized as a single token
239 --
240 -- * Comments are not treated properly
241 lex :: ReadS String             -- As defined by H98
242 lex s  = readP_to_S L.hsLex s
243
244 -- | Read a string representation of a character, using Haskell
245 -- source-language escape conventions.  For example:
246 --
247 -- > lexLitChar  "\\nHello"  =  [("\\n", "Hello")]
248 --
249 lexLitChar :: ReadS String      -- As defined by H98
250 lexLitChar = readP_to_S (do { (s, _) <- P.gather L.lexChar ;
251                               return s })
252         -- There was a skipSpaces before the P.gather L.lexChar,
253         -- but that seems inconsistent with readLitChar
254
255 -- | Read a string representation of a character, using Haskell
256 -- source-language escape conventions, and convert it to the character
257 -- that it encodes.  For example:
258 --
259 -- > readLitChar "\\nHello"  =  [('\n', "Hello")]
260 --
261 readLitChar :: ReadS Char       -- As defined by H98
262 readLitChar = readP_to_S L.lexChar
263
264 -- | Reads a non-empty string of decimal digits.
265 lexDigits :: ReadS String
266 lexDigits = readP_to_S (P.munch1 isDigit)
267
268 ------------------------------------------------------------------------
269 -- utility parsers
270
271 lexP :: ReadPrec L.Lexeme
272 -- ^ Parse a single lexeme
273 lexP = lift L.lex
274
275 paren :: ReadPrec a -> ReadPrec a
276 -- ^ @(paren p)@ parses \"(P0)\"
277 --      where @p@ parses \"P0\" in precedence context zero
278 paren p = do L.Punc "(" <- lexP
279              x          <- reset p
280              L.Punc ")" <- lexP
281              return x
282
283 parens :: ReadPrec a -> ReadPrec a
284 -- ^ @(parens p)@ parses \"P\", \"(P0)\", \"((P0))\", etc, 
285 --      where @p@ parses \"P\"  in the current precedence context
286 --          and parses \"P0\" in precedence context zero
287 parens p = optional
288  where
289   optional  = p +++ mandatory
290   mandatory = paren optional
291
292 list :: ReadPrec a -> ReadPrec [a]
293 -- ^ @(list p)@ parses a list of things parsed by @p@,
294 -- using the usual square-bracket syntax.
295 list readx =
296   parens
297   ( do L.Punc "[" <- lexP
298        (listRest False +++ listNext)
299   )
300  where
301   listRest started =
302     do L.Punc c <- lexP
303        case c of
304          "]"           -> return []
305          "," | started -> listNext
306          _             -> pfail
307   
308   listNext =
309     do x  <- reset readx
310        xs <- listRest True
311        return (x:xs)
312
313 choose :: [(String, ReadPrec a)] -> ReadPrec a
314 -- ^ Parse the specified lexeme and continue as specified.
315 -- Esp useful for nullary constructors; e.g.
316 --    @choose [(\"A\", return A), (\"B\", return B)]@
317 choose sps = foldr ((+++) . try_one) pfail sps
318            where
319              try_one (s,p) = do { L.Ident s' <- lexP ;
320                                   if s == s' then p else pfail }
321 \end{code}
322
323
324 %*********************************************************
325 %*                                                      *
326 \subsection{Simple instances of Read}
327 %*                                                      *
328 %*********************************************************
329
330 \begin{code}
331 instance Read Char where
332   readPrec =
333     parens
334     ( do L.Char c <- lexP
335          return c
336     )
337
338   readListPrec =
339     parens
340     ( do L.String s <- lexP     -- Looks for "foo"
341          return s
342      +++
343       readListPrecDefault       -- Looks for ['f','o','o']
344     )                           -- (more generous than H98 spec)
345
346   readList = readListDefault
347
348 instance Read Bool where
349   readPrec =
350     parens
351     ( do L.Ident s <- lexP
352          case s of
353            "True"  -> return True
354            "False" -> return False
355            _       -> pfail
356     )
357
358   readListPrec = readListPrecDefault
359   readList     = readListDefault
360
361 instance Read Ordering where
362   readPrec =
363     parens
364     ( do L.Ident s <- lexP
365          case s of
366            "LT" -> return LT
367            "EQ" -> return EQ
368            "GT" -> return GT
369            _    -> pfail
370     )
371
372   readListPrec = readListPrecDefault
373   readList     = readListDefault
374 \end{code}
375
376
377 %*********************************************************
378 %*                                                      *
379 \subsection{Structure instances of Read: Maybe, List etc}
380 %*                                                      *
381 %*********************************************************
382
383 For structured instances of Read we start using the precedences.  The
384 idea is then that 'parens (prec k p)' will fail immediately when trying
385 to parse it in a context with a higher precedence level than k. But if
386 there is one parenthesis parsed, then the required precedence level
387 drops to 0 again, and parsing inside p may succeed.
388
389 'appPrec' is just the precedence level of function application.  So,
390 if we are parsing function application, we'd better require the
391 precedence level to be at least 'appPrec'. Otherwise, we have to put
392 parentheses around it.
393
394 'step' is used to increase the precedence levels inside a
395 parser, and can be used to express left- or right- associativity. For
396 example, % is defined to be left associative, so we only increase
397 precedence on the right hand side.
398
399 Note how step is used in for example the Maybe parser to increase the
400 precedence beyond appPrec, so that basically only literals and
401 parenthesis-like objects such as (...) and [...] can be an argument to
402 'Just'.
403
404 \begin{code}
405 instance Read a => Read (Maybe a) where
406   readPrec =
407     parens
408     (do L.Ident "Nothing" <- lexP
409         return Nothing
410      +++
411      prec appPrec (
412         do L.Ident "Just" <- lexP
413            x              <- step readPrec
414            return (Just x))
415     )
416
417   readListPrec = readListPrecDefault
418   readList     = readListDefault
419
420 instance Read a => Read [a] where
421   readPrec     = readListPrec
422   readListPrec = readListPrecDefault
423   readList     = readListDefault
424
425 instance  (Ix a, Read a, Read b) => Read (Array a b)  where
426     readPrec = parens $ prec appPrec $
427                do L.Ident "array" <- lexP
428                   theBounds <- step readPrec
429                   vals   <- step readPrec
430                   return (array theBounds vals)
431
432     readListPrec = readListPrecDefault
433     readList     = readListDefault
434
435 instance Read L.Lexeme where
436   readPrec     = lexP
437   readListPrec = readListPrecDefault
438   readList     = readListDefault
439 \end{code}
440
441
442 %*********************************************************
443 %*                                                      *
444 \subsection{Numeric instances of Read}
445 %*                                                      *
446 %*********************************************************
447
448 \begin{code}
449 readNumber :: Num a => (L.Lexeme -> Maybe a) -> ReadPrec a
450 -- Read a signed number
451 readNumber convert =
452   parens
453   ( do x <- lexP
454        case x of
455          L.Symbol "-" -> do n <- readNumber convert
456                             return (negate n)
457        
458          _   -> case convert x of
459                    Just n  -> return n
460                    Nothing -> pfail
461   )
462
463 convertInt :: Num a => L.Lexeme -> Maybe a
464 convertInt (L.Int i) = Just (fromInteger i)
465 convertInt _         = Nothing
466
467 convertFrac :: Fractional a => L.Lexeme -> Maybe a
468 convertFrac (L.Int i) = Just (fromInteger i)
469 convertFrac (L.Rat r) = Just (fromRational r)
470 convertFrac _         = Nothing
471
472 instance Read Int where
473   readPrec     = readNumber convertInt
474   readListPrec = readListPrecDefault
475   readList     = readListDefault
476
477 instance Read Integer where
478   readPrec     = readNumber convertInt
479   readListPrec = readListPrecDefault
480   readList     = readListDefault
481
482 instance Read Float where
483   readPrec     = readNumber convertFrac
484   readListPrec = readListPrecDefault
485   readList     = readListDefault
486
487 instance Read Double where
488   readPrec     = readNumber convertFrac
489   readListPrec = readListPrecDefault
490   readList     = readListDefault
491
492 instance (Integral a, Read a) => Read (Ratio a) where
493   readPrec =
494     parens
495     ( prec ratioPrec
496       ( do x            <- step readPrec
497            L.Symbol "%" <- lexP
498            y            <- step readPrec
499            return (x % y)
500       )
501     )
502
503   readListPrec = readListPrecDefault
504   readList     = readListDefault
505 \end{code}
506
507
508 %*********************************************************
509 %*                                                      *
510         Tuple instances of Read, up to size 15
511 %*                                                      *
512 %*********************************************************
513
514 \begin{code}
515 instance Read () where
516   readPrec =
517     parens
518     ( paren
519       ( return ()
520       )
521     )
522
523   readListPrec = readListPrecDefault
524   readList     = readListDefault
525
526 instance (Read a, Read b) => Read (a,b) where
527   readPrec = wrap_tup read_tup2
528   readListPrec = readListPrecDefault
529   readList     = readListDefault
530
531 wrap_tup :: ReadPrec a -> ReadPrec a
532 wrap_tup p = parens (paren p)
533
534 read_comma :: ReadPrec ()
535 read_comma = do { L.Punc "," <- lexP; return () }
536
537 read_tup2 :: (Read a, Read b) => ReadPrec (a,b)
538 -- Reads "a , b"  no parens!
539 read_tup2 = do x <- readPrec
540                read_comma
541                y <- readPrec
542                return (x,y)
543
544 read_tup4 :: (Read a, Read b, Read c, Read d) => ReadPrec (a,b,c,d)
545 read_tup4 = do  (a,b) <- read_tup2
546                 read_comma
547                 (c,d) <- read_tup2
548                 return (a,b,c,d)
549
550
551 read_tup8 :: (Read a, Read b, Read c, Read d, Read e, Read f, Read g, Read h)
552           => ReadPrec (a,b,c,d,e,f,g,h)
553 read_tup8 = do  (a,b,c,d) <- read_tup4
554                 read_comma
555                 (e,f,g,h) <- read_tup4
556                 return (a,b,c,d,e,f,g,h)
557
558
559 instance (Read a, Read b, Read c) => Read (a, b, c) where
560   readPrec = wrap_tup (do { (a,b) <- read_tup2; read_comma 
561                           ; c <- readPrec 
562                           ; return (a,b,c) })
563   readListPrec = readListPrecDefault
564   readList     = readListDefault
565
566 instance (Read a, Read b, Read c, Read d) => Read (a, b, c, d) where
567   readPrec = wrap_tup read_tup4
568   readListPrec = readListPrecDefault
569   readList     = readListDefault
570
571 instance (Read a, Read b, Read c, Read d, Read e) => Read (a, b, c, d, e) where
572   readPrec = wrap_tup (do { (a,b,c,d) <- read_tup4; read_comma
573                           ; e <- readPrec
574                           ; return (a,b,c,d,e) })
575   readListPrec = readListPrecDefault
576   readList     = readListDefault
577
578 instance (Read a, Read b, Read c, Read d, Read e, Read f)
579         => Read (a, b, c, d, e, f) where
580   readPrec = wrap_tup (do { (a,b,c,d) <- read_tup4; read_comma
581                           ; (e,f) <- read_tup2
582                           ; return (a,b,c,d,e,f) })
583   readListPrec = readListPrecDefault
584   readList     = readListDefault
585
586 instance (Read a, Read b, Read c, Read d, Read e, Read f, Read g)
587         => Read (a, b, c, d, e, f, g) where
588   readPrec = wrap_tup (do { (a,b,c,d) <- read_tup4; read_comma
589                           ; (e,f) <- read_tup2; read_comma
590                           ; g <- readPrec
591                           ; return (a,b,c,d,e,f,g) })
592   readListPrec = readListPrecDefault
593   readList     = readListDefault
594
595 instance (Read a, Read b, Read c, Read d, Read e, Read f, Read g, Read h)
596         => Read (a, b, c, d, e, f, g, h) where
597   readPrec     = wrap_tup read_tup8
598   readListPrec = readListPrecDefault
599   readList     = readListDefault
600
601 instance (Read a, Read b, Read c, Read d, Read e, Read f, Read g, Read h,
602           Read i)
603         => Read (a, b, c, d, e, f, g, h, i) where
604   readPrec = wrap_tup (do { (a,b,c,d,e,f,g,h) <- read_tup8; read_comma
605                           ; i <- readPrec
606                           ; return (a,b,c,d,e,f,g,h,i) })
607   readListPrec = readListPrecDefault
608   readList     = readListDefault
609
610 instance (Read a, Read b, Read c, Read d, Read e, Read f, Read g, Read h,
611           Read i, Read j)
612         => Read (a, b, c, d, e, f, g, h, i, j) where
613   readPrec = wrap_tup (do { (a,b,c,d,e,f,g,h) <- read_tup8; read_comma
614                           ; (i,j) <- read_tup2
615                           ; return (a,b,c,d,e,f,g,h,i,j) })
616   readListPrec = readListPrecDefault
617   readList     = readListDefault
618
619 instance (Read a, Read b, Read c, Read d, Read e, Read f, Read g, Read h,
620           Read i, Read j, Read k)
621         => Read (a, b, c, d, e, f, g, h, i, j, k) where
622   readPrec = wrap_tup (do { (a,b,c,d,e,f,g,h) <- read_tup8; read_comma
623                           ; (i,j) <- read_tup2; read_comma
624                           ; k <- readPrec
625                           ; return (a,b,c,d,e,f,g,h,i,j,k) })
626   readListPrec = readListPrecDefault
627   readList     = readListDefault
628
629 instance (Read a, Read b, Read c, Read d, Read e, Read f, Read g, Read h,
630           Read i, Read j, Read k, Read l)
631         => Read (a, b, c, d, e, f, g, h, i, j, k, l) where
632   readPrec = wrap_tup (do { (a,b,c,d,e,f,g,h) <- read_tup8; read_comma
633                           ; (i,j,k,l) <- read_tup4
634                           ; return (a,b,c,d,e,f,g,h,i,j,k,l) })
635   readListPrec = readListPrecDefault
636   readList     = readListDefault
637
638 instance (Read a, Read b, Read c, Read d, Read e, Read f, Read g, Read h,
639           Read i, Read j, Read k, Read l, Read m)
640         => Read (a, b, c, d, e, f, g, h, i, j, k, l, m) where
641   readPrec = wrap_tup (do { (a,b,c,d,e,f,g,h) <- read_tup8; read_comma
642                           ; (i,j,k,l) <- read_tup4; read_comma
643                           ; m <- readPrec
644                           ; return (a,b,c,d,e,f,g,h,i,j,k,l,m) })
645   readListPrec = readListPrecDefault
646   readList     = readListDefault
647
648 instance (Read a, Read b, Read c, Read d, Read e, Read f, Read g, Read h,
649           Read i, Read j, Read k, Read l, Read m, Read n)
650         => Read (a, b, c, d, e, f, g, h, i, j, k, l, m, n) where
651   readPrec = wrap_tup (do { (a,b,c,d,e,f,g,h) <- read_tup8; read_comma
652                           ; (i,j,k,l) <- read_tup4; read_comma
653                           ; (m,n) <- read_tup2
654                           ; return (a,b,c,d,e,f,g,h,i,j,k,l,m,n) })
655   readListPrec = readListPrecDefault
656   readList     = readListDefault
657
658 instance (Read a, Read b, Read c, Read d, Read e, Read f, Read g, Read h,
659           Read i, Read j, Read k, Read l, Read m, Read n, Read o)
660         => Read (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) where
661   readPrec = wrap_tup (do { (a,b,c,d,e,f,g,h) <- read_tup8; read_comma
662                           ; (i,j,k,l) <- read_tup4; read_comma
663                           ; (m,n) <- read_tup2; read_comma
664                           ; o <- readPrec
665                           ; return (a,b,c,d,e,f,g,h,i,j,k,l,m,n,o) })
666   readListPrec = readListPrecDefault
667   readList     = readListDefault
668 \end{code}
669
670 \begin{code}
671 -- XXX Can this be removed?
672
673 readp :: Read a => ReadP a
674 readp = readPrec_to_P readPrec minPrec
675 \end{code}
676