[project @ 2005-10-22 00:37:01 by ross]
[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' in Haskell 98 is equivalent to
137 --
138 -- > instance (Read a) => Read (Tree a) where
139 -- >
140 -- >         readsPrec d r =  readParen (d > app_prec)
141 -- >                          (\r -> [(Leaf m,t) |
142 -- >                                  ("Leaf",s) <- lex r,
143 -- >                                  (m,t) <- readsPrec (app_prec+1) s]) r
144 -- >
145 -- >                       ++ readParen (d > up_prec)
146 -- >                          (\r -> [(u:^:v,w) |
147 -- >                                  (u,s) <- readsPrec (up_prec+1) r,
148 -- >                                  (":^:",t) <- lex s,
149 -- >                                  (v,w) <- readsPrec (up_prec+1) t]) r
150 -- >
151 -- >           where app_prec = 10
152 -- >                 up_prec = 5
153 --
154 -- Note that right-associativity of @:^:@ is unused.
155 --
156 -- The derived instance in GHC is equivalent to
157 --
158 -- > instance (Read a) => Read (Tree a) where
159 -- >
160 -- >         readPrec = parens $ (prec app_prec $ do
161 -- >                                  Ident "Leaf" <- lexP
162 -- >                                  m <- step readPrec
163 -- >                                  return (Leaf m))
164 -- >
165 -- >                      +++ (prec up_prec $ do
166 -- >                                  u <- step readPrec
167 -- >                                  Symbol ":^:" <- lexP
168 -- >                                  v <- step readPrec
169 -- >                                  return (u :^: v))
170 -- >
171 -- >           where app_prec = 10
172 -- >                 up_prec = 5
173 -- >
174 -- >         readListPrec = readListPrecDefault
175
176 class Read a where
177   -- | attempts to parse a value from the front of the string, returning
178   -- a list of (parsed value, remaining string) pairs.  If there is no
179   -- successful parse, the returned list is empty.
180   --
181   -- Derived instances of 'Read' and 'Text.Show.Show' satisfy the following:
182   --
183   -- * @(x,\"\")@ is an element of
184   --   @('readsPrec' d ('Text.Show.showsPrec' d x \"\"))@.
185   --
186   -- That is, 'readsPrec' parses the string produced by
187   -- 'Text.Show.showsPrec', and delivers the value that
188   -- 'Text.Show.showsPrec' started with.
189
190   readsPrec    :: Int   -- ^ the operator precedence of the enclosing
191                         -- context (a number from @0@ to @11@).
192                         -- Function application has precedence @10@.
193                 -> ReadS a
194
195   -- | The method 'readList' is provided to allow the programmer to
196   -- give a specialised way of parsing lists of values.
197   -- For example, this is used by the predefined 'Read' instance of
198   -- the 'Char' type, where values of type 'String' should be are
199   -- expected to use double quotes, rather than square brackets.
200   readList     :: ReadS [a]
201
202   -- | Proposed replacement for 'readsPrec' using new-style parsers (GHC only).
203   readPrec     :: ReadPrec a
204
205   -- | Proposed replacement for 'readList' using new-style parsers (GHC only).
206   -- The default definition uses 'readList'.  Instances that define 'readPrec'
207   -- should also define 'readListPrec' as 'readListPrecDefault'.
208   readListPrec :: ReadPrec [a]
209   
210   -- default definitions
211   readsPrec    = readPrec_to_S readPrec
212   readList     = readPrec_to_S (list readPrec) 0
213   readPrec     = readS_to_Prec readsPrec
214   readListPrec = readS_to_Prec (\_ -> readList)
215
216 readListDefault :: Read a => ReadS [a]
217 -- ^ A possible replacement definition for the 'readList' method (GHC only).
218 --   This is only needed for GHC, and even then only for 'Read' instances
219 --   where 'readListPrec' isn't defined as 'readListPrecDefault'.
220 readListDefault = readPrec_to_S readListPrec 0
221
222 readListPrecDefault :: Read a => ReadPrec [a]
223 -- ^ A possible replacement definition for the 'readListPrec' method,
224 --   defined using 'readPrec' (GHC only).
225 readListPrecDefault = list readPrec
226
227 ------------------------------------------------------------------------
228 -- utility functions
229
230 -- | equivalent to 'readsPrec' with a precedence of 0.
231 reads :: Read a => ReadS a
232 reads = readsPrec minPrec
233
234 readp :: Read a => ReadP a
235 readp = readPrec_to_P readPrec minPrec
236
237 readEither :: Read a => String -> Either String a
238 readEither s =
239   case [ x | (x,"") <- readPrec_to_S read' minPrec s ] of
240     [x] -> Right x
241     []  -> Left "Prelude.read: no parse"
242     _   -> Left "Prelude.read: ambiguous parse"
243  where
244   read' =
245     do x <- readPrec
246        lift P.skipSpaces
247        return x
248
249 -- | The 'read' function reads input from a string, which must be
250 -- completely consumed by the input process.
251 read :: Read a => String -> a
252 read s = either error id (readEither s)
253
254 ------------------------------------------------------------------------
255 -- H98 compatibility
256
257 -- | The 'lex' function reads a single lexeme from the input, discarding
258 -- initial white space, and returning the characters that constitute the
259 -- lexeme.  If the input string contains only white space, 'lex' returns a
260 -- single successful \`lexeme\' consisting of the empty string.  (Thus
261 -- @'lex' \"\" = [(\"\",\"\")]@.)  If there is no legal lexeme at the
262 -- beginning of the input string, 'lex' fails (i.e. returns @[]@).
263 --
264 -- This lexer is not completely faithful to the Haskell lexical syntax
265 -- in the following respects:
266 --
267 -- * Qualified names are not handled properly
268 --
269 -- * Octal and hexadecimal numerics are not recognized as a single token
270 --
271 -- * Comments are not treated properly
272 lex :: ReadS String             -- As defined by H98
273 lex s  = readP_to_S L.hsLex s
274
275 -- | Read a string representation of a character, using Haskell
276 -- source-language escape conventions.  For example:
277 --
278 -- > lexLitChar  "\\nHello"  =  [("\\n", "Hello")]
279 --
280 lexLitChar :: ReadS String      -- As defined by H98
281 lexLitChar = readP_to_S (do { (s, _) <- P.gather L.lexChar ;
282                               return s })
283         -- There was a skipSpaces before the P.gather L.lexChar,
284         -- but that seems inconsistent with readLitChar
285
286 -- | Read a string representation of a character, using Haskell
287 -- source-language escape conventions, and convert it to the character
288 -- that it encodes.  For example:
289 --
290 -- > readLitChar "\\nHello"  =  [('\n', "Hello")]
291 --
292 readLitChar :: ReadS Char       -- As defined by H98
293 readLitChar = readP_to_S L.lexChar
294
295 -- | Reads a non-empty string of decimal digits.
296 lexDigits :: ReadS String
297 lexDigits = readP_to_S (P.munch1 isDigit)
298
299 ------------------------------------------------------------------------
300 -- utility parsers
301
302 lexP :: ReadPrec L.Lexeme
303 -- ^ Parse a single lexeme
304 lexP = lift L.lex
305
306 paren :: ReadPrec a -> ReadPrec a
307 -- ^ @(paren p)@ parses \"(P0)\"
308 --      where @p@ parses \"P0\" in precedence context zero
309 paren p = do L.Punc "(" <- lexP
310              x          <- reset p
311              L.Punc ")" <- lexP
312              return x
313
314 parens :: ReadPrec a -> ReadPrec a
315 -- ^ @(parens p)@ parses \"P\", \"(P0)\", \"((P0))\", etc, 
316 --      where @p@ parses \"P\"  in the current precedence context
317 --          and parses \"P0\" in precedence context zero
318 parens p = optional
319  where
320   optional  = p +++ mandatory
321   mandatory = paren optional
322
323 list :: ReadPrec a -> ReadPrec [a]
324 -- ^ @(list p)@ parses a list of things parsed by @p@,
325 -- using the usual square-bracket syntax.
326 list readx =
327   parens
328   ( do L.Punc "[" <- lexP
329        (listRest False +++ listNext)
330   )
331  where
332   listRest started =
333     do L.Punc c <- lexP
334        case c of
335          "]"           -> return []
336          "," | started -> listNext
337          _             -> pfail
338   
339   listNext =
340     do x  <- reset readx
341        xs <- listRest True
342        return (x:xs)
343
344 choose :: [(String, ReadPrec a)] -> ReadPrec a
345 -- ^ Parse the specified lexeme and continue as specified.
346 -- Esp useful for nullary constructors; e.g.
347 --    @choose [(\"A\", return A), (\"B\", return B)]@
348 choose sps = foldr ((+++) . try_one) pfail sps
349            where
350              try_one (s,p) = do { L.Ident s' <- lexP ;
351                                   if s == s' then p else pfail }
352 \end{code}
353
354
355 %*********************************************************
356 %*                                                      *
357 \subsection{Simple instances of Read}
358 %*                                                      *
359 %*********************************************************
360
361 \begin{code}
362 instance Read Char where
363   readPrec =
364     parens
365     ( do L.Char c <- lexP
366          return c
367     )
368
369   readListPrec =
370     parens
371     ( do L.String s <- lexP     -- Looks for "foo"
372          return s
373      +++
374       readListPrecDefault       -- Looks for ['f','o','o']
375     )                           -- (more generous than H98 spec)
376
377   readList = readListDefault
378
379 instance Read Bool where
380   readPrec =
381     parens
382     ( do L.Ident s <- lexP
383          case s of
384            "True"  -> return True
385            "False" -> return False
386            _       -> pfail
387     )
388
389   readListPrec = readListPrecDefault
390   readList     = readListDefault
391
392 instance Read Ordering where
393   readPrec =
394     parens
395     ( do L.Ident s <- lexP
396          case s of
397            "LT" -> return LT
398            "EQ" -> return EQ
399            "GT" -> return GT
400            _    -> pfail
401     )
402
403   readListPrec = readListPrecDefault
404   readList     = readListDefault
405 \end{code}
406
407
408 %*********************************************************
409 %*                                                      *
410 \subsection{Structure instances of Read: Maybe, List etc}
411 %*                                                      *
412 %*********************************************************
413
414 For structured instances of Read we start using the precedences.  The
415 idea is then that 'parens (prec k p)' will fail immediately when trying
416 to parse it in a context with a higher precedence level than k. But if
417 there is one parenthesis parsed, then the required precedence level
418 drops to 0 again, and parsing inside p may succeed.
419
420 'appPrec' is just the precedence level of function application.  So,
421 if we are parsing function application, we'd better require the
422 precedence level to be at least 'appPrec'. Otherwise, we have to put
423 parentheses around it.
424
425 'step' is used to increase the precedence levels inside a
426 parser, and can be used to express left- or right- associativity. For
427 example, % is defined to be left associative, so we only increase
428 precedence on the right hand side.
429
430 Note how step is used in for example the Maybe parser to increase the
431 precedence beyond appPrec, so that basically only literals and
432 parenthesis-like objects such as (...) and [...] can be an argument to
433 'Just'.
434
435 \begin{code}
436 instance Read a => Read (Maybe a) where
437   readPrec =
438     parens
439     (do L.Ident "Nothing" <- lexP
440         return Nothing
441      +++
442      prec appPrec (
443         do L.Ident "Just" <- lexP
444            x              <- step readPrec
445            return (Just x))
446     )
447
448   readListPrec = readListPrecDefault
449   readList     = readListDefault
450
451 instance (Read a, Read b) => Read (Either a b) where
452   readPrec =
453     parens
454     ( prec appPrec
455       ( do L.Ident "Left" <- lexP
456            x            <- step readPrec
457            return (Left x)
458        +++
459         do L.Ident "Right" <- lexP
460            y             <- step readPrec
461            return (Right y)
462       )
463     )
464
465   readListPrec = readListPrecDefault
466   readList     = readListDefault
467
468 instance Read a => Read [a] where
469   readPrec     = readListPrec
470   readListPrec = readListPrecDefault
471   readList     = readListDefault
472
473 instance  (Ix a, Read a, Read b) => Read (Array a b)  where
474     readPrec = parens $ prec appPrec $
475                do L.Ident "array" <- lexP
476                   bounds <- step readPrec
477                   vals   <- step readPrec
478                   return (array bounds vals)
479
480     readListPrec = readListPrecDefault
481     readList     = readListDefault
482
483 instance Read L.Lexeme where
484   readPrec     = lexP
485   readListPrec = readListPrecDefault
486   readList     = readListDefault
487 \end{code}
488
489
490 %*********************************************************
491 %*                                                      *
492 \subsection{Numeric instances of Read}
493 %*                                                      *
494 %*********************************************************
495
496 \begin{code}
497 readNumber :: Num a => (L.Lexeme -> Maybe a) -> ReadPrec a
498 -- Read a signed number
499 readNumber convert =
500   parens
501   ( do x <- lexP
502        case x of
503          L.Symbol "-" -> do n <- readNumber convert
504                             return (negate n)
505        
506          _   -> case convert x of
507                    Just n  -> return n
508                    Nothing -> pfail
509   )
510
511 convertInt :: Num a => L.Lexeme -> Maybe a
512 convertInt (L.Int i) = Just (fromInteger i)
513 convertInt _         = Nothing
514
515 convertFrac :: Fractional a => L.Lexeme -> Maybe a
516 convertFrac (L.Int i) = Just (fromInteger i)
517 convertFrac (L.Rat r) = Just (fromRational r)
518 convertFrac _         = Nothing
519
520 instance Read Int where
521   readPrec     = readNumber convertInt
522   readListPrec = readListPrecDefault
523   readList     = readListDefault
524
525 instance Read Integer where
526   readPrec     = readNumber convertInt
527   readListPrec = readListPrecDefault
528   readList     = readListDefault
529
530 instance Read Float where
531   readPrec     = readNumber convertFrac
532   readListPrec = readListPrecDefault
533   readList     = readListDefault
534
535 instance Read Double where
536   readPrec     = readNumber convertFrac
537   readListPrec = readListPrecDefault
538   readList     = readListDefault
539
540 instance (Integral a, Read a) => Read (Ratio a) where
541   readPrec =
542     parens
543     ( prec ratioPrec
544       ( do x            <- step readPrec
545            L.Symbol "%" <- lexP
546            y            <- step readPrec
547            return (x % y)
548       )
549     )
550
551   readListPrec = readListPrecDefault
552   readList     = readListDefault
553 \end{code}
554
555
556 %*********************************************************
557 %*                                                      *
558         Tuple instances of Read, up to size 15
559 %*                                                      *
560 %*********************************************************
561
562 \begin{code}
563 instance Read () where
564   readPrec =
565     parens
566     ( paren
567       ( return ()
568       )
569     )
570
571   readListPrec = readListPrecDefault
572   readList     = readListDefault
573
574 instance (Read a, Read b) => Read (a,b) where
575   readPrec = wrap_tup read_tup2
576   readListPrec = readListPrecDefault
577   readList     = readListDefault
578
579 wrap_tup :: ReadPrec a -> ReadPrec a
580 wrap_tup p = parens (paren p)
581
582 read_comma :: ReadPrec ()
583 read_comma = do { L.Punc "," <- lexP; return () }
584
585 read_tup2 :: (Read a, Read b) => ReadPrec (a,b)
586 -- Reads "a , b"  no parens!
587 read_tup2 = do x <- readPrec
588                read_comma
589                y <- readPrec
590                return (x,y)
591
592 read_tup4 :: (Read a, Read b, Read c, Read d) => ReadPrec (a,b,c,d)
593 read_tup4 = do  (a,b) <- read_tup2
594                 read_comma
595                 (c,d) <- read_tup2
596                 return (a,b,c,d)
597
598
599 read_tup8 :: (Read a, Read b, Read c, Read d, Read e, Read f, Read g, Read h)
600           => ReadPrec (a,b,c,d,e,f,g,h)
601 read_tup8 = do  (a,b,c,d) <- read_tup4
602                 read_comma
603                 (e,f,g,h) <- read_tup4
604                 return (a,b,c,d,e,f,g,h)
605
606
607 instance (Read a, Read b, Read c) => Read (a, b, c) where
608   readPrec = wrap_tup (do { (a,b) <- read_tup2; read_comma 
609                           ; c <- readPrec 
610                           ; return (a,b,c) })
611   readListPrec = readListPrecDefault
612   readList     = readListDefault
613
614 instance (Read a, Read b, Read c, Read d) => Read (a, b, c, d) where
615   readPrec = wrap_tup read_tup4
616   readListPrec = readListPrecDefault
617   readList     = readListDefault
618
619 instance (Read a, Read b, Read c, Read d, Read e) => Read (a, b, c, d, e) where
620   readPrec = wrap_tup (do { (a,b,c,d) <- read_tup4; read_comma
621                           ; e <- readPrec
622                           ; return (a,b,c,d,e) })
623   readListPrec = readListPrecDefault
624   readList     = readListDefault
625
626 instance (Read a, Read b, Read c, Read d, Read e, Read f)
627         => Read (a, b, c, d, e, f) where
628   readPrec = wrap_tup (do { (a,b,c,d) <- read_tup4; read_comma
629                           ; (e,f) <- read_tup2
630                           ; return (a,b,c,d,e,f) })
631   readListPrec = readListPrecDefault
632   readList     = readListDefault
633
634 instance (Read a, Read b, Read c, Read d, Read e, Read f, Read g)
635         => Read (a, b, c, d, e, f, g) where
636   readPrec = wrap_tup (do { (a,b,c,d) <- read_tup4; read_comma
637                           ; (e,f) <- read_tup2; read_comma
638                           ; g <- readPrec
639                           ; return (a,b,c,d,e,f,g) })
640   readListPrec = readListPrecDefault
641   readList     = readListDefault
642
643 instance (Read a, Read b, Read c, Read d, Read e, Read f, Read g, Read h)
644         => Read (a, b, c, d, e, f, g, h) where
645   readPrec     = wrap_tup read_tup8
646   readListPrec = readListPrecDefault
647   readList     = readListDefault
648
649 instance (Read a, Read b, Read c, Read d, Read e, Read f, Read g, Read h,
650           Read i)
651         => Read (a, b, c, d, e, f, g, h, i) where
652   readPrec = wrap_tup (do { (a,b,c,d,e,f,g,h) <- read_tup8; read_comma
653                           ; i <- readPrec
654                           ; return (a,b,c,d,e,f,g,h,i) })
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)
660         => Read (a, b, c, d, e, f, g, h, i, j) where
661   readPrec = wrap_tup (do { (a,b,c,d,e,f,g,h) <- read_tup8; read_comma
662                           ; (i,j) <- read_tup2
663                           ; return (a,b,c,d,e,f,g,h,i,j) })
664   readListPrec = readListPrecDefault
665   readList     = readListDefault
666
667 instance (Read a, Read b, Read c, Read d, Read e, Read f, Read g, Read h,
668           Read i, Read j, Read k)
669         => Read (a, b, c, d, e, f, g, h, i, j, k) where
670   readPrec = wrap_tup (do { (a,b,c,d,e,f,g,h) <- read_tup8; read_comma
671                           ; (i,j) <- read_tup2; read_comma
672                           ; k <- readPrec
673                           ; return (a,b,c,d,e,f,g,h,i,j,k) })
674   readListPrec = readListPrecDefault
675   readList     = readListDefault
676
677 instance (Read a, Read b, Read c, Read d, Read e, Read f, Read g, Read h,
678           Read i, Read j, Read k, Read l)
679         => Read (a, b, c, d, e, f, g, h, i, j, k, l) where
680   readPrec = wrap_tup (do { (a,b,c,d,e,f,g,h) <- read_tup8; read_comma
681                           ; (i,j,k,l) <- read_tup4
682                           ; return (a,b,c,d,e,f,g,h,i,j,k,l) })
683   readListPrec = readListPrecDefault
684   readList     = readListDefault
685
686 instance (Read a, Read b, Read c, Read d, Read e, Read f, Read g, Read h,
687           Read i, Read j, Read k, Read l, Read m)
688         => Read (a, b, c, d, e, f, g, h, i, j, k, l, m) where
689   readPrec = wrap_tup (do { (a,b,c,d,e,f,g,h) <- read_tup8; read_comma
690                           ; (i,j,k,l) <- read_tup4; read_comma
691                           ; m <- readPrec
692                           ; return (a,b,c,d,e,f,g,h,i,j,k,l,m) })
693   readListPrec = readListPrecDefault
694   readList     = readListDefault
695
696 instance (Read a, Read b, Read c, Read d, Read e, Read f, Read g, Read h,
697           Read i, Read j, Read k, Read l, Read m, Read n)
698         => Read (a, b, c, d, e, f, g, h, i, j, k, l, m, n) where
699   readPrec = wrap_tup (do { (a,b,c,d,e,f,g,h) <- read_tup8; read_comma
700                           ; (i,j,k,l) <- read_tup4; read_comma
701                           ; (m,n) <- read_tup2
702                           ; return (a,b,c,d,e,f,g,h,i,j,k,l,m,n) })
703   readListPrec = readListPrecDefault
704   readList     = readListDefault
705
706 instance (Read a, Read b, Read c, Read d, Read e, Read f, Read g, Read h,
707           Read i, Read j, Read k, Read l, Read m, Read n, Read o)
708         => Read (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) where
709   readPrec = wrap_tup (do { (a,b,c,d,e,f,g,h) <- read_tup8; read_comma
710                           ; (i,j,k,l) <- read_tup4; read_comma
711                           ; (m,n) <- read_tup2; read_comma
712                           ; o <- readPrec
713                           ; return (a,b,c,d,e,f,g,h,i,j,k,l,m,n,o) })
714   readListPrec = readListPrecDefault
715   readList     = readListDefault
716 \end{code}