f7870a2df1e50ad3fc3e4e116ad85a0aee95933d
[ghc.git] / libraries / base / GHC / Read.hs
1 {-# LANGUAGE Trustworthy #-}
2 {-# LANGUAGE CPP, NoImplicitPrelude, StandaloneDeriving, ScopedTypeVariables #-}
3 {-# OPTIONS_HADDOCK hide #-}
4
5 -----------------------------------------------------------------------------
6 -- |
7 -- Module : GHC.Read
8 -- Copyright : (c) The University of Glasgow, 1994-2002
9 -- License : see libraries/base/LICENSE
10 --
11 -- Maintainer : cvs-ghc@haskell.org
12 -- Stability : internal
13 -- Portability : non-portable (GHC Extensions)
14 --
15 -- The 'Read' class and instances for basic data types.
16 --
17 -----------------------------------------------------------------------------
18
19 module GHC.Read
20 ( Read(..) -- class
21
22 -- ReadS type
23 , ReadS
24
25 -- H2010 compatibility
26 , lex
27 , lexLitChar
28 , readLitChar
29 , lexDigits
30
31 -- defining readers
32 , lexP, expectP
33 , paren
34 , parens
35 , list
36 , choose
37 , readListDefault, readListPrecDefault
38 , readNumber
39 , readField
40 , readFieldHash
41 , readSymField
42
43 -- Temporary
44 , readParen
45 )
46 where
47
48 #include "MachDeps.h"
49
50 import qualified Text.ParserCombinators.ReadP as P
51
52 import Text.ParserCombinators.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
67 import GHC.Unicode
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 import GHC.Word
75
76
77 -- | @'readParen' 'True' p@ parses what @p@ parses, but surrounded with
78 -- parentheses.
79 --
80 -- @'readParen' 'False' p@ parses what @p@ parses, but optionally
81 -- surrounded with parentheses.
82 readParen :: Bool -> ReadS a -> ReadS a
83 -- A Haskell 2010 function
84 readParen b g = if b then mandatory else optional
85 where optional r = g r ++ mandatory r
86 mandatory r = do
87 ("(",s) <- lex r
88 (x,t) <- optional s
89 (")",u) <- lex t
90 return (x,u)
91
92 -- | Parsing of 'String's, producing values.
93 --
94 -- Derived instances of 'Read' make the following assumptions, which
95 -- derived instances of 'Text.Show.Show' obey:
96 --
97 -- * If the constructor is defined to be an infix operator, then the
98 -- derived 'Read' instance will parse only infix applications of
99 -- the constructor (not the prefix form).
100 --
101 -- * Associativity is not used to reduce the occurrence of parentheses,
102 -- although precedence may be.
103 --
104 -- * If the constructor is defined using record syntax, the derived 'Read'
105 -- will parse only the record-syntax form, and furthermore, the fields
106 -- must be given in the same order as the original declaration.
107 --
108 -- * The derived 'Read' instance allows arbitrary Haskell whitespace
109 -- between tokens of the input string. Extra parentheses are also
110 -- allowed.
111 --
112 -- For example, given the declarations
113 --
114 -- > infixr 5 :^:
115 -- > data Tree a = Leaf a | Tree a :^: Tree a
116 --
117 -- the derived instance of 'Read' in Haskell 2010 is equivalent to
118 --
119 -- > instance (Read a) => Read (Tree a) where
120 -- >
121 -- > readsPrec d r = readParen (d > app_prec)
122 -- > (\r -> [(Leaf m,t) |
123 -- > ("Leaf",s) <- lex r,
124 -- > (m,t) <- readsPrec (app_prec+1) s]) r
125 -- >
126 -- > ++ readParen (d > up_prec)
127 -- > (\r -> [(u:^:v,w) |
128 -- > (u,s) <- readsPrec (up_prec+1) r,
129 -- > (":^:",t) <- lex s,
130 -- > (v,w) <- readsPrec (up_prec+1) t]) r
131 -- >
132 -- > where app_prec = 10
133 -- > up_prec = 5
134 --
135 -- Note that right-associativity of @:^:@ is unused.
136 --
137 -- The derived instance in GHC is equivalent to
138 --
139 -- > instance (Read a) => Read (Tree a) where
140 -- >
141 -- > readPrec = parens $ (prec app_prec $ do
142 -- > Ident "Leaf" <- lexP
143 -- > m <- step readPrec
144 -- > return (Leaf m))
145 -- >
146 -- > +++ (prec up_prec $ do
147 -- > u <- step readPrec
148 -- > Symbol ":^:" <- lexP
149 -- > v <- step readPrec
150 -- > return (u :^: v))
151 -- >
152 -- > where app_prec = 10
153 -- > up_prec = 5
154 -- >
155 -- > readListPrec = readListPrecDefault
156 --
157 -- Why do both 'readsPrec' and 'readPrec' exist, and why does GHC opt to
158 -- implement 'readPrec' in derived 'Read' instances instead of 'readsPrec'?
159 -- The reason is that 'readsPrec' is based on the 'ReadS' type, and although
160 -- 'ReadS' is mentioned in the Haskell 2010 Report, it is not a very efficient
161 -- parser data structure.
162 --
163 -- 'readPrec', on the other hand, is based on a much more efficient 'ReadPrec'
164 -- datatype (a.k.a \"new-style parsers\"), but its definition relies on the use
165 -- of the @RankNTypes@ language extension. Therefore, 'readPrec' (and its
166 -- cousin, 'readListPrec') are marked as GHC-only. Nevertheless, it is
167 -- recommended to use 'readPrec' instead of 'readsPrec' whenever possible
168 -- for the efficiency improvements it brings.
169 --
170 -- As mentioned above, derived 'Read' instances in GHC will implement
171 -- 'readPrec' instead of 'readsPrec'. The default implementations of
172 -- 'readsPrec' (and its cousin, 'readList') will simply use 'readPrec' under
173 -- the hood. If you are writing a 'Read' instance by hand, it is recommended
174 -- to write it like so:
175 --
176 -- @
177 -- instance 'Read' T where
178 -- 'readPrec' = ...
179 -- 'readListPrec' = 'readListPrecDefault'
180 -- @
181
182 class Read a where
183 {-# MINIMAL readsPrec | readPrec #-}
184
185 -- | attempts to parse a value from the front of the string, returning
186 -- a list of (parsed value, remaining string) pairs. If there is no
187 -- successful parse, the returned list is empty.
188 --
189 -- Derived instances of 'Read' and 'Text.Show.Show' satisfy the following:
190 --
191 -- * @(x,\"\")@ is an element of
192 -- @('readsPrec' d ('Text.Show.showsPrec' d x \"\"))@.
193 --
194 -- That is, 'readsPrec' parses the string produced by
195 -- 'Text.Show.showsPrec', and delivers the value that
196 -- 'Text.Show.showsPrec' started with.
197
198 readsPrec :: Int -- ^ the operator precedence of the enclosing
199 -- context (a number from @0@ to @11@).
200 -- Function application has precedence @10@.
201 -> ReadS a
202
203 -- | The method 'readList' is provided to allow the programmer to
204 -- give a specialised way of parsing lists of values.
205 -- For example, this is used by the predefined 'Read' instance of
206 -- the 'Char' type, where values of type 'String' should be are
207 -- expected to use double quotes, rather than square brackets.
208 readList :: ReadS [a]
209
210 -- | Proposed replacement for 'readsPrec' using new-style parsers (GHC only).
211 readPrec :: ReadPrec a
212
213 -- | Proposed replacement for 'readList' using new-style parsers (GHC only).
214 -- The default definition uses 'readList'. Instances that define 'readPrec'
215 -- should also define 'readListPrec' as 'readListPrecDefault'.
216 readListPrec :: ReadPrec [a]
217
218 -- default definitions
219 readsPrec = readPrec_to_S readPrec
220 readList = readPrec_to_S (list readPrec) 0
221 readPrec = readS_to_Prec readsPrec
222 readListPrec = readS_to_Prec (\_ -> readList)
223
224 readListDefault :: Read a => ReadS [a]
225 -- ^ A possible replacement definition for the 'readList' method (GHC only).
226 -- This is only needed for GHC, and even then only for 'Read' instances
227 -- where 'readListPrec' isn't defined as 'readListPrecDefault'.
228 readListDefault = readPrec_to_S readListPrec 0
229
230 readListPrecDefault :: Read a => ReadPrec [a]
231 -- ^ A possible replacement definition for the 'readListPrec' method,
232 -- defined using 'readPrec' (GHC only).
233 readListPrecDefault = list readPrec
234
235 ------------------------------------------------------------------------
236 -- H2010 compatibility
237
238 -- | The 'lex' function reads a single lexeme from the input, discarding
239 -- initial white space, and returning the characters that constitute the
240 -- lexeme. If the input string contains only white space, 'lex' returns a
241 -- single successful \`lexeme\' consisting of the empty string. (Thus
242 -- @'lex' \"\" = [(\"\",\"\")]@.) If there is no legal lexeme at the
243 -- beginning of the input string, 'lex' fails (i.e. returns @[]@).
244 --
245 -- This lexer is not completely faithful to the Haskell lexical syntax
246 -- in the following respects:
247 --
248 -- * Qualified names are not handled properly
249 --
250 -- * Octal and hexadecimal numerics are not recognized as a single token
251 --
252 -- * Comments are not treated properly
253 lex :: ReadS String -- As defined by H2010
254 lex s = readP_to_S L.hsLex s
255
256 -- | Read a string representation of a character, using Haskell
257 -- source-language escape conventions. For example:
258 --
259 -- > lexLitChar "\\nHello" = [("\\n", "Hello")]
260 --
261 lexLitChar :: ReadS String -- As defined by H2010
262 lexLitChar = readP_to_S (do { (s, _) <- P.gather L.lexChar ;
263 let s' = removeNulls s in
264 return s' })
265 where
266 -- remove nulls from end of the character if they exist
267 removeNulls [] = []
268 removeNulls ('\\':'&':xs) = removeNulls xs
269 removeNulls (first:rest) = first : removeNulls rest
270 -- There was a skipSpaces before the P.gather L.lexChar,
271 -- but that seems inconsistent with readLitChar
272
273 -- | Read a string representation of a character, using Haskell
274 -- source-language escape conventions, and convert it to the character
275 -- that it encodes. For example:
276 --
277 -- > readLitChar "\\nHello" = [('\n', "Hello")]
278 --
279 readLitChar :: ReadS Char -- As defined by H2010
280 readLitChar = readP_to_S L.lexChar
281
282 -- | Reads a non-empty string of decimal digits.
283 lexDigits :: ReadS String
284 lexDigits = readP_to_S (P.munch1 isDigit)
285
286 ------------------------------------------------------------------------
287 -- utility parsers
288
289 lexP :: ReadPrec L.Lexeme
290 -- ^ Parse a single lexeme
291 lexP = lift L.lex
292
293 expectP :: L.Lexeme -> ReadPrec ()
294 expectP lexeme = lift (L.expect lexeme)
295
296 expectCharP :: Char -> ReadPrec a -> ReadPrec a
297 expectCharP c a = do
298 q <- get
299 if q == c
300 then a
301 else pfail
302 {-# INLINE expectCharP #-}
303
304 skipSpacesThenP :: ReadPrec a -> ReadPrec a
305 skipSpacesThenP m =
306 do s <- look
307 skip s
308 where
309 skip (c:s) | isSpace c = get *> skip s
310 skip _ = m
311
312 paren :: ReadPrec a -> ReadPrec a
313 -- ^ @(paren p)@ parses \"(P0)\"
314 -- where @p@ parses \"P0\" in precedence context zero
315 paren p = skipSpacesThenP (paren' p)
316
317 paren' :: ReadPrec a -> ReadPrec a
318 paren' p = expectCharP '(' $ reset p >>= \x ->
319 skipSpacesThenP (expectCharP ')' (pure x))
320
321 parens :: ReadPrec a -> ReadPrec a
322 -- ^ @(parens p)@ parses \"P\", \"(P0)\", \"((P0))\", etc,
323 -- where @p@ parses \"P\" in the current precedence context
324 -- and parses \"P0\" in precedence context zero
325 parens p = optional
326 where
327 optional = skipSpacesThenP (p +++ mandatory)
328 mandatory = paren' optional
329
330 list :: ReadPrec a -> ReadPrec [a]
331 -- ^ @(list p)@ parses a list of things parsed by @p@,
332 -- using the usual square-bracket syntax.
333 list readx =
334 parens
335 ( do expectP (L.Punc "[")
336 (listRest False +++ listNext)
337 )
338 where
339 listRest started =
340 do L.Punc c <- lexP
341 case c of
342 "]" -> return []
343 "," | started -> listNext
344 _ -> pfail
345
346 listNext =
347 do x <- reset readx
348 xs <- listRest True
349 return (x:xs)
350
351 choose :: [(String, ReadPrec a)] -> ReadPrec a
352 -- ^ Parse the specified lexeme and continue as specified.
353 -- Esp useful for nullary constructors; e.g.
354 -- @choose [(\"A\", return A), (\"B\", return B)]@
355 -- We match both Ident and Symbol because the constructor
356 -- might be an operator eg @(:~:)@
357 choose sps = foldr ((+++) . try_one) pfail sps
358 where
359 try_one (s,p) = do { token <- lexP ;
360 case token of
361 L.Ident s' | s==s' -> p
362 L.Symbol s' | s==s' -> p
363 _other -> pfail }
364
365 -- See Note [Why readField]
366
367 -- | 'Read' parser for a record field, of the form @fieldName=value@. The
368 -- @fieldName@ must be an alphanumeric identifier; for symbols (operator-style)
369 -- field names, e.g. @(#)@, use 'readSymField'). The second argument is a
370 -- parser for the field value.
371 readField :: String -> ReadPrec a -> ReadPrec a
372 readField fieldName readVal = do
373 expectP (L.Ident fieldName)
374 expectP (L.Punc "=")
375 readVal
376 {-# NOINLINE readField #-}
377
378 -- See Note [Why readField]
379
380 -- | 'Read' parser for a record field, of the form @fieldName#=value@. That is,
381 -- an alphanumeric identifier @fieldName@ followed by the symbol @#@. The
382 -- second argument is a parser for the field value.
383 --
384 -- Note that 'readField' does not suffice for this purpose due to
385 -- <https://ghc.haskell.org/trac/ghc/ticket/5041 Trac #5041>.
386 readFieldHash :: String -> ReadPrec a -> ReadPrec a
387 readFieldHash fieldName readVal = do
388 expectP (L.Ident fieldName)
389 expectP (L.Symbol "#")
390 expectP (L.Punc "=")
391 readVal
392 {-# NOINLINE readFieldHash #-}
393
394 -- See Note [Why readField]
395
396 -- | 'Read' parser for a symbol record field, of the form @(###)=value@ (where
397 -- @###@ is the field name). The field name must be a symbol (operator-style),
398 -- e.g. @(#)@. For regular (alphanumeric) field names, use 'readField'. The
399 -- second argument is a parser for the field value.
400 readSymField :: String -> ReadPrec a -> ReadPrec a
401 readSymField fieldName readVal = do
402 expectP (L.Punc "(")
403 expectP (L.Symbol fieldName)
404 expectP (L.Punc ")")
405 expectP (L.Punc "=")
406 readVal
407 {-# NOINLINE readSymField #-}
408
409
410 -- Note [Why readField]
411 --
412 -- Previously, the code for automatically deriving Read instance (in
413 -- typecheck/TcGenDeriv.hs) would generate inline code for parsing fields;
414 -- this, however, turned out to produce massive amounts of intermediate code,
415 -- and produced a considerable performance hit in the code generator.
416 -- Since Read instances are not generally supposed to be perfomance critical,
417 -- the readField and readSymField functions have been factored out, and the
418 -- code generator now just generates calls rather than manually inlining the
419 -- parsers. For large record types (e.g. 500 fields), this produces a
420 -- significant performance boost.
421 --
422 -- See also Trac #14364.
423
424
425 --------------------------------------------------------------
426 -- Simple instances of Read
427 --------------------------------------------------------------
428
429 -- | @since 2.01
430 deriving instance Read GeneralCategory
431
432 -- | @since 2.01
433 instance Read Char where
434 readPrec =
435 parens
436 ( do L.Char c <- lexP
437 return c
438 )
439
440 readListPrec =
441 parens
442 ( do L.String s <- lexP -- Looks for "foo"
443 return s
444 +++
445 readListPrecDefault -- Looks for ['f','o','o']
446 ) -- (more generous than H2010 spec)
447
448 readList = readListDefault
449
450 -- | @since 2.01
451 instance Read Bool where
452 readPrec =
453 parens
454 ( do L.Ident s <- lexP
455 case s of
456 "True" -> return True
457 "False" -> return False
458 _ -> pfail
459 )
460
461 readListPrec = readListPrecDefault
462 readList = readListDefault
463
464 -- | @since 2.01
465 instance Read Ordering where
466 readPrec =
467 parens
468 ( do L.Ident s <- lexP
469 case s of
470 "LT" -> return LT
471 "EQ" -> return EQ
472 "GT" -> return GT
473 _ -> pfail
474 )
475
476 readListPrec = readListPrecDefault
477 readList = readListDefault
478
479 -- | @since 4.11.0.0
480 deriving instance Read a => Read (NonEmpty a)
481
482 --------------------------------------------------------------
483 -- Structure instances of Read: Maybe, List etc
484 --------------------------------------------------------------
485
486 {-
487 For structured instances of Read we start using the precedences. The
488 idea is then that 'parens (prec k p)' will fail immediately when trying
489 to parse it in a context with a higher precedence level than k. But if
490 there is one parenthesis parsed, then the required precedence level
491 drops to 0 again, and parsing inside p may succeed.
492
493 'appPrec' is just the precedence level of function application. So,
494 if we are parsing function application, we'd better require the
495 precedence level to be at least 'appPrec'. Otherwise, we have to put
496 parentheses around it.
497
498 'step' is used to increase the precedence levels inside a
499 parser, and can be used to express left- or right- associativity. For
500 example, % is defined to be left associative, so we only increase
501 precedence on the right hand side.
502
503 Note how step is used in for example the Maybe parser to increase the
504 precedence beyond appPrec, so that basically only literals and
505 parenthesis-like objects such as (...) and [...] can be an argument to
506 'Just'.
507 -}
508
509 -- | @since 2.01
510 instance Read a => Read (Maybe a) where
511 readPrec =
512 parens
513 (do expectP (L.Ident "Nothing")
514 return Nothing
515 +++
516 prec appPrec (
517 do expectP (L.Ident "Just")
518 x <- step readPrec
519 return (Just x))
520 )
521
522 readListPrec = readListPrecDefault
523 readList = readListDefault
524
525 -- | @since 2.01
526 instance Read a => Read [a] where
527 {-# SPECIALISE instance Read [String] #-}
528 {-# SPECIALISE instance Read [Char] #-}
529 {-# SPECIALISE instance Read [Int] #-}
530 readPrec = readListPrec
531 readListPrec = readListPrecDefault
532 readList = readListDefault
533
534 -- | @since 2.01
535 instance (Ix a, Read a, Read b) => Read (Array a b) where
536 readPrec = parens $ prec appPrec $
537 do expectP (L.Ident "array")
538 theBounds <- step readPrec
539 vals <- step readPrec
540 return (array theBounds vals)
541
542 readListPrec = readListPrecDefault
543 readList = readListDefault
544
545 -- | @since 2.01
546 instance Read L.Lexeme where
547 readPrec = lexP
548 readListPrec = readListPrecDefault
549 readList = readListDefault
550
551 --------------------------------------------------------------
552 -- Numeric instances of Read
553 --------------------------------------------------------------
554
555 readNumber :: Num a => (L.Lexeme -> ReadPrec a) -> ReadPrec a
556 -- Read a signed number
557 readNumber convert =
558 parens
559 ( do x <- lexP
560 case x of
561 L.Symbol "-" -> do y <- lexP
562 n <- convert y
563 return (negate n)
564
565 _ -> convert x
566 )
567
568
569 convertInt :: Num a => L.Lexeme -> ReadPrec a
570 convertInt (L.Number n)
571 | Just i <- L.numberToInteger n = return (fromInteger i)
572 convertInt _ = pfail
573
574 convertFrac :: forall a . RealFloat a => L.Lexeme -> ReadPrec a
575 convertFrac (L.Ident "NaN") = return (0 / 0)
576 convertFrac (L.Ident "Infinity") = return (1 / 0)
577 convertFrac (L.Number n) = let resRange = floatRange (undefined :: a)
578 in case L.numberToRangedRational resRange n of
579 Nothing -> return (1 / 0)
580 Just rat -> return $ fromRational rat
581 convertFrac _ = pfail
582
583 -- | @since 2.01
584 instance Read Int where
585 readPrec = readNumber convertInt
586 readListPrec = readListPrecDefault
587 readList = readListDefault
588
589 -- | @since 4.5.0.0
590 instance Read Word where
591 readsPrec p s = [(fromInteger x, r) | (x, r) <- readsPrec p s]
592
593 -- | @since 2.01
594 instance Read Word8 where
595 readsPrec p s = [(fromIntegral (x::Int), r) | (x, r) <- readsPrec p s]
596
597 -- | @since 2.01
598 instance Read Word16 where
599 readsPrec p s = [(fromIntegral (x::Int), r) | (x, r) <- readsPrec p s]
600
601 -- | @since 2.01
602 instance Read Word32 where
603 #if WORD_SIZE_IN_BITS < 33
604 readsPrec p s = [(fromInteger x, r) | (x, r) <- readsPrec p s]
605 #else
606 readsPrec p s = [(fromIntegral (x::Int), r) | (x, r) <- readsPrec p s]
607 #endif
608
609 -- | @since 2.01
610 instance Read Word64 where
611 readsPrec p s = [(fromInteger x, r) | (x, r) <- readsPrec p s]
612
613 -- | @since 2.01
614 instance Read Integer where
615 readPrec = readNumber convertInt
616 readListPrec = readListPrecDefault
617 readList = readListDefault
618
619 -- | @since 2.01
620 instance Read Float where
621 readPrec = readNumber convertFrac
622 readListPrec = readListPrecDefault
623 readList = readListDefault
624
625 -- | @since 2.01
626 instance Read Double where
627 readPrec = readNumber convertFrac
628 readListPrec = readListPrecDefault
629 readList = readListDefault
630
631 -- | @since 2.01
632 instance (Integral a, Read a) => Read (Ratio a) where
633 readPrec =
634 parens
635 ( prec ratioPrec
636 ( do x <- step readPrec
637 expectP (L.Symbol "%")
638 y <- step readPrec
639 return (x % y)
640 )
641 )
642
643 readListPrec = readListPrecDefault
644 readList = readListDefault
645
646
647 ------------------------------------------------------------------------
648 -- Tuple instances of Read, up to size 15
649 ------------------------------------------------------------------------
650
651 -- | @since 2.01
652 instance Read () where
653 readPrec =
654 parens
655 ( paren
656 ( return ()
657 )
658 )
659
660 readListPrec = readListPrecDefault
661 readList = readListDefault
662
663 -- | @since 2.01
664 instance (Read a, Read b) => Read (a,b) where
665 readPrec = wrap_tup read_tup2
666 readListPrec = readListPrecDefault
667 readList = readListDefault
668
669 wrap_tup :: ReadPrec a -> ReadPrec a
670 wrap_tup p = parens (paren p)
671
672 read_comma :: ReadPrec ()
673 read_comma = expectP (L.Punc ",")
674
675 read_tup2 :: (Read a, Read b) => ReadPrec (a,b)
676 -- Reads "a , b" no parens!
677 read_tup2 = do x <- readPrec
678 read_comma
679 y <- readPrec
680 return (x,y)
681
682 read_tup4 :: (Read a, Read b, Read c, Read d) => ReadPrec (a,b,c,d)
683 read_tup4 = do (a,b) <- read_tup2
684 read_comma
685 (c,d) <- read_tup2
686 return (a,b,c,d)
687
688
689 read_tup8 :: (Read a, Read b, Read c, Read d, Read e, Read f, Read g, Read h)
690 => ReadPrec (a,b,c,d,e,f,g,h)
691 read_tup8 = do (a,b,c,d) <- read_tup4
692 read_comma
693 (e,f,g,h) <- read_tup4
694 return (a,b,c,d,e,f,g,h)
695
696
697 -- | @since 2.01
698 instance (Read a, Read b, Read c) => Read (a, b, c) where
699 readPrec = wrap_tup (do { (a,b) <- read_tup2; read_comma
700 ; c <- readPrec
701 ; return (a,b,c) })
702 readListPrec = readListPrecDefault
703 readList = readListDefault
704
705 -- | @since 2.01
706 instance (Read a, Read b, Read c, Read d) => Read (a, b, c, d) where
707 readPrec = wrap_tup read_tup4
708 readListPrec = readListPrecDefault
709 readList = readListDefault
710
711 -- | @since 2.01
712 instance (Read a, Read b, Read c, Read d, Read e) => Read (a, b, c, d, e) where
713 readPrec = wrap_tup (do { (a,b,c,d) <- read_tup4; read_comma
714 ; e <- readPrec
715 ; return (a,b,c,d,e) })
716 readListPrec = readListPrecDefault
717 readList = readListDefault
718
719 -- | @since 2.01
720 instance (Read a, Read b, Read c, Read d, Read e, Read f)
721 => Read (a, b, c, d, e, f) where
722 readPrec = wrap_tup (do { (a,b,c,d) <- read_tup4; read_comma
723 ; (e,f) <- read_tup2
724 ; return (a,b,c,d,e,f) })
725 readListPrec = readListPrecDefault
726 readList = readListDefault
727
728 -- | @since 2.01
729 instance (Read a, Read b, Read c, Read d, Read e, Read f, Read g)
730 => Read (a, b, c, d, e, f, g) where
731 readPrec = wrap_tup (do { (a,b,c,d) <- read_tup4; read_comma
732 ; (e,f) <- read_tup2; read_comma
733 ; g <- readPrec
734 ; return (a,b,c,d,e,f,g) })
735 readListPrec = readListPrecDefault
736 readList = readListDefault
737
738 -- | @since 2.01
739 instance (Read a, Read b, Read c, Read d, Read e, Read f, Read g, Read h)
740 => Read (a, b, c, d, e, f, g, h) where
741 readPrec = wrap_tup read_tup8
742 readListPrec = readListPrecDefault
743 readList = readListDefault
744
745 -- | @since 2.01
746 instance (Read a, Read b, Read c, Read d, Read e, Read f, Read g, Read h,
747 Read i)
748 => Read (a, b, c, d, e, f, g, h, i) where
749 readPrec = wrap_tup (do { (a,b,c,d,e,f,g,h) <- read_tup8; read_comma
750 ; i <- readPrec
751 ; return (a,b,c,d,e,f,g,h,i) })
752 readListPrec = readListPrecDefault
753 readList = readListDefault
754
755 -- | @since 2.01
756 instance (Read a, Read b, Read c, Read d, Read e, Read f, Read g, Read h,
757 Read i, Read j)
758 => Read (a, b, c, d, e, f, g, h, i, j) where
759 readPrec = wrap_tup (do { (a,b,c,d,e,f,g,h) <- read_tup8; read_comma
760 ; (i,j) <- read_tup2
761 ; return (a,b,c,d,e,f,g,h,i,j) })
762 readListPrec = readListPrecDefault
763 readList = readListDefault
764
765 -- | @since 2.01
766 instance (Read a, Read b, Read c, Read d, Read e, Read f, Read g, Read h,
767 Read i, Read j, Read k)
768 => Read (a, b, c, d, e, f, g, h, i, j, k) where
769 readPrec = wrap_tup (do { (a,b,c,d,e,f,g,h) <- read_tup8; read_comma
770 ; (i,j) <- read_tup2; read_comma
771 ; k <- readPrec
772 ; return (a,b,c,d,e,f,g,h,i,j,k) })
773 readListPrec = readListPrecDefault
774 readList = readListDefault
775
776 -- | @since 2.01
777 instance (Read a, Read b, Read c, Read d, Read e, Read f, Read g, Read h,
778 Read i, Read j, Read k, Read l)
779 => Read (a, b, c, d, e, f, g, h, i, j, k, l) where
780 readPrec = wrap_tup (do { (a,b,c,d,e,f,g,h) <- read_tup8; read_comma
781 ; (i,j,k,l) <- read_tup4
782 ; return (a,b,c,d,e,f,g,h,i,j,k,l) })
783 readListPrec = readListPrecDefault
784 readList = readListDefault
785
786 -- | @since 2.01
787 instance (Read a, Read b, Read c, Read d, Read e, Read f, Read g, Read h,
788 Read i, Read j, Read k, Read l, Read m)
789 => Read (a, b, c, d, e, f, g, h, i, j, k, l, m) where
790 readPrec = wrap_tup (do { (a,b,c,d,e,f,g,h) <- read_tup8; read_comma
791 ; (i,j,k,l) <- read_tup4; read_comma
792 ; m <- readPrec
793 ; return (a,b,c,d,e,f,g,h,i,j,k,l,m) })
794 readListPrec = readListPrecDefault
795 readList = readListDefault
796
797 -- | @since 2.01
798 instance (Read a, Read b, Read c, Read d, Read e, Read f, Read g, Read h,
799 Read i, Read j, Read k, Read l, Read m, Read n)
800 => Read (a, b, c, d, e, f, g, h, i, j, k, l, m, n) where
801 readPrec = wrap_tup (do { (a,b,c,d,e,f,g,h) <- read_tup8; read_comma
802 ; (i,j,k,l) <- read_tup4; read_comma
803 ; (m,n) <- read_tup2
804 ; return (a,b,c,d,e,f,g,h,i,j,k,l,m,n) })
805 readListPrec = readListPrecDefault
806 readList = readListDefault
807
808 -- | @since 2.01
809 instance (Read a, Read b, Read c, Read d, Read e, Read f, Read g, Read h,
810 Read i, Read j, Read k, Read l, Read m, Read n, Read o)
811 => Read (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) where
812 readPrec = wrap_tup (do { (a,b,c,d,e,f,g,h) <- read_tup8; read_comma
813 ; (i,j,k,l) <- read_tup4; read_comma
814 ; (m,n) <- read_tup2; read_comma
815 ; o <- readPrec
816 ; return (a,b,c,d,e,f,g,h,i,j,k,l,m,n,o) })
817 readListPrec = readListPrecDefault
818 readList = readListDefault