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