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