{-# LANGUAGE Trustworthy #-}
{-# LANGUAGE CPP, NoImplicitPrelude, StandaloneDeriving, ScopedTypeVariables #-}
{-# OPTIONS_HADDOCK not-home #-}

-----------------------------------------------------------------------------
-- |
-- Module      :  GHC.Read
-- Copyright   :  (c) The University of Glasgow, 1994-2002
-- License     :  see libraries/base/LICENSE
--
-- Maintainer  :  cvs-ghc@haskell.org
-- Stability   :  internal
-- Portability :  non-portable (GHC Extensions)
--
-- The 'Read' class and instances for basic data types.
--
-----------------------------------------------------------------------------

module GHC.Read
  ( Read(..)   -- class

  -- ReadS type
  , ReadS

  -- H2010 compatibility
  , lex
  , lexLitChar
  , readLitChar
  , lexDigits

  -- defining readers
  , lexP, expectP
  , paren
  , parens
  , list
  , choose
  , readListDefault, readListPrecDefault
  , readNumber
  , readField
  , readFieldHash
  , readSymField

  -- Temporary
  , readParen
  )
 where

#include "MachDeps.h"

import qualified Text.ParserCombinators.ReadP as P

import Text.ParserCombinators.ReadP
  ( ReadS
  , readP_to_S
  )

import qualified Text.Read.Lex as L
-- Lex exports 'lex', which is also defined here,
-- hence the qualified import.
-- We can't import *anything* unqualified, because that
-- confuses Haddock.

import Text.ParserCombinators.ReadPrec

import Data.Maybe

import GHC.Unicode
import GHC.Num
import GHC.Real
import GHC.Float
import GHC.Show
import GHC.Base
import GHC.Arr
import GHC.Word
import GHC.List (filter)
import GHC.Tuple (Solo (..))


-- | @'readParen' 'True' p@ parses what @p@ parses, but surrounded with
-- parentheses.
--
-- @'readParen' 'False' p@ parses what @p@ parses, but optionally
-- surrounded with parentheses.
readParen       :: Bool -> ReadS a -> ReadS a
-- A Haskell 2010 function
readParen :: forall a. Bool -> ReadS a -> ReadS a
readParen Bool
b ReadS a
g   =  if Bool
b then ReadS a
mandatory else ReadS a
optional
                   where optional :: ReadS a
optional String
r  = ReadS a
g String
r forall a. [a] -> [a] -> [a]
++ ReadS a
mandatory String
r
                         mandatory :: ReadS a
mandatory String
r = do
                                (String
"(",String
s) <- ReadS String
lex String
r
                                (a
x,String
t)   <- ReadS a
optional String
s
                                (String
")",String
u) <- ReadS String
lex String
t
                                forall (m :: * -> *) a. Monad m => a -> m a
return (a
x,String
u)

-- | Parsing of 'String's, producing values.
--
-- Derived instances of 'Read' make the following assumptions, which
-- derived instances of 'Text.Show.Show' obey:
--
-- * If the constructor is defined to be an infix operator, then the
--   derived 'Read' instance will parse only infix applications of
--   the constructor (not the prefix form).
--
-- * Associativity is not used to reduce the occurrence of parentheses,
--   although precedence may be.
--
-- * If the constructor is defined using record syntax, the derived 'Read'
--   will parse only the record-syntax form, and furthermore, the fields
--   must be given in the same order as the original declaration.
--
-- * The derived 'Read' instance allows arbitrary Haskell whitespace
--   between tokens of the input string.  Extra parentheses are also
--   allowed.
--
-- For example, given the declarations
--
-- > infixr 5 :^:
-- > data Tree a =  Leaf a  |  Tree a :^: Tree a
--
-- the derived instance of 'Read' in Haskell 2010 is equivalent to
--
-- > instance (Read a) => Read (Tree a) where
-- >
-- >         readsPrec d r =  readParen (d > app_prec)
-- >                          (\r -> [(Leaf m,t) |
-- >                                  ("Leaf",s) <- lex r,
-- >                                  (m,t) <- readsPrec (app_prec+1) s]) r
-- >
-- >                       ++ readParen (d > up_prec)
-- >                          (\r -> [(u:^:v,w) |
-- >                                  (u,s) <- readsPrec (up_prec+1) r,
-- >                                  (":^:",t) <- lex s,
-- >                                  (v,w) <- readsPrec (up_prec+1) t]) r
-- >
-- >           where app_prec = 10
-- >                 up_prec = 5
--
-- Note that right-associativity of @:^:@ is unused.
--
-- The derived instance in GHC is equivalent to
--
-- > instance (Read a) => Read (Tree a) where
-- >
-- >         readPrec = parens $ (prec app_prec $ do
-- >                                  Ident "Leaf" <- lexP
-- >                                  m <- step readPrec
-- >                                  return (Leaf m))
-- >
-- >                      +++ (prec up_prec $ do
-- >                                  u <- step readPrec
-- >                                  Symbol ":^:" <- lexP
-- >                                  v <- step readPrec
-- >                                  return (u :^: v))
-- >
-- >           where app_prec = 10
-- >                 up_prec = 5
-- >
-- >         readListPrec = readListPrecDefault
--
-- Why do both 'readsPrec' and 'readPrec' exist, and why does GHC opt to
-- implement 'readPrec' in derived 'Read' instances instead of 'readsPrec'?
-- The reason is that 'readsPrec' is based on the 'ReadS' type, and although
-- 'ReadS' is mentioned in the Haskell 2010 Report, it is not a very efficient
-- parser data structure.
--
-- 'readPrec', on the other hand, is based on a much more efficient 'ReadPrec'
-- datatype (a.k.a \"new-style parsers\"), but its definition relies on the use
-- of the @RankNTypes@ language extension. Therefore, 'readPrec' (and its
-- cousin, 'readListPrec') are marked as GHC-only. Nevertheless, it is
-- recommended to use 'readPrec' instead of 'readsPrec' whenever possible
-- for the efficiency improvements it brings.
--
-- As mentioned above, derived 'Read' instances in GHC will implement
-- 'readPrec' instead of 'readsPrec'. The default implementations of
-- 'readsPrec' (and its cousin, 'readList') will simply use 'readPrec' under
-- the hood. If you are writing a 'Read' instance by hand, it is recommended
-- to write it like so:
--
-- @
-- instance 'Read' T where
--   'readPrec'     = ...
--   'readListPrec' = 'readListPrecDefault'
-- @

class Read a where
  {-# MINIMAL readsPrec | readPrec #-}

  -- | attempts to parse a value from the front of the string, returning
  -- a list of (parsed value, remaining string) pairs.  If there is no
  -- successful parse, the returned list is empty.
  --
  -- Derived instances of 'Read' and 'Text.Show.Show' satisfy the following:
  --
  -- * @(x,\"\")@ is an element of
  --   @('readsPrec' d ('Text.Show.showsPrec' d x \"\"))@.
  --
  -- That is, 'readsPrec' parses the string produced by
  -- 'Text.Show.showsPrec', and delivers the value that
  -- 'Text.Show.showsPrec' started with.

  readsPrec    :: Int   -- ^ the operator precedence of the enclosing
                        -- context (a number from @0@ to @11@).
                        -- Function application has precedence @10@.
                -> ReadS a

  -- | The method 'readList' is provided to allow the programmer to
  -- give a specialised way of parsing lists of values.
  -- For example, this is used by the predefined 'Read' instance of
  -- the 'Char' type, where values of type 'String' should be are
  -- expected to use double quotes, rather than square brackets.
  readList     :: ReadS [a]

  -- | Proposed replacement for 'readsPrec' using new-style parsers (GHC only).
  readPrec     :: ReadPrec a

  -- | Proposed replacement for 'readList' using new-style parsers (GHC only).
  -- The default definition uses 'readList'.  Instances that define 'readPrec'
  -- should also define 'readListPrec' as 'readListPrecDefault'.
  readListPrec :: ReadPrec [a]

  -- default definitions
  readsPrec    = forall a. ReadPrec a -> Int -> ReadS a
readPrec_to_S forall a. Read a => ReadPrec a
readPrec
  readList     = forall a. ReadPrec a -> Int -> ReadS a
readPrec_to_S (forall a. ReadPrec a -> ReadPrec [a]
list forall a. Read a => ReadPrec a
readPrec) Int
0
  readPrec     = forall a. (Int -> ReadS a) -> ReadPrec a
readS_to_Prec forall a. Read a => Int -> ReadS a
readsPrec
  readListPrec = forall a. (Int -> ReadS a) -> ReadPrec a
readS_to_Prec (\Int
_ -> forall a. Read a => ReadS [a]
readList)

readListDefault :: Read a => ReadS [a]
-- ^ A possible replacement definition for the 'readList' method (GHC only).
--   This is only needed for GHC, and even then only for 'Read' instances
--   where 'readListPrec' isn't defined as 'readListPrecDefault'.
readListDefault :: forall a. Read a => ReadS [a]
readListDefault = forall a. ReadPrec a -> Int -> ReadS a
readPrec_to_S forall a. Read a => ReadPrec [a]
readListPrec Int
0

readListPrecDefault :: Read a => ReadPrec [a]
-- ^ A possible replacement definition for the 'readListPrec' method,
--   defined using 'readPrec' (GHC only).
readListPrecDefault :: forall a. Read a => ReadPrec [a]
readListPrecDefault = forall a. ReadPrec a -> ReadPrec [a]
list forall a. Read a => ReadPrec a
readPrec

------------------------------------------------------------------------
-- H2010 compatibility

-- | The 'lex' function reads a single lexeme from the input, discarding
-- initial white space, and returning the characters that constitute the
-- lexeme.  If the input string contains only white space, 'lex' returns a
-- single successful \`lexeme\' consisting of the empty string.  (Thus
-- @'lex' \"\" = [(\"\",\"\")]@.)  If there is no legal lexeme at the
-- beginning of the input string, 'lex' fails (i.e. returns @[]@).
--
-- This lexer is not completely faithful to the Haskell lexical syntax
-- in the following respects:
--
-- * Qualified names are not handled properly
--
-- * Octal and hexadecimal numerics are not recognized as a single token
--
-- * Comments are not treated properly
lex :: ReadS String             -- As defined by H2010
lex :: ReadS String
lex String
s  = forall a. ReadP a -> ReadS a
readP_to_S ReadP String
L.hsLex String
s

-- | Read a string representation of a character, using Haskell
-- source-language escape conventions.  For example:
--
-- > lexLitChar  "\\nHello"  =  [("\\n", "Hello")]
--
lexLitChar :: ReadS String      -- As defined by H2010
lexLitChar :: ReadS String
lexLitChar = forall a. ReadP a -> ReadS a
readP_to_S (do { (String
s, Char
_) <- forall a. ReadP a -> ReadP (String, a)
P.gather ReadP Char
L.lexChar ;
                              let s' :: String
s' = String -> String
removeNulls String
s in
                              forall (m :: * -> *) a. Monad m => a -> m a
return String
s' })
    where
    -- remove nulls from end of the character if they exist
    removeNulls :: String -> String
removeNulls [] = []
    removeNulls (Char
'\\':Char
'&':String
xs) = String -> String
removeNulls String
xs
    removeNulls (Char
first:String
rest) = Char
first forall a. a -> [a] -> [a]
: String -> String
removeNulls String
rest
        -- There was a skipSpaces before the P.gather L.lexChar,
        -- but that seems inconsistent with readLitChar

-- | Read a string representation of a character, using Haskell
-- source-language escape conventions, and convert it to the character
-- that it encodes.  For example:
--
-- > readLitChar "\\nHello"  =  [('\n', "Hello")]
--
readLitChar :: ReadS Char       -- As defined by H2010
readLitChar :: ReadS Char
readLitChar = forall a. ReadP a -> ReadS a
readP_to_S ReadP Char
L.lexChar

-- | Reads a non-empty string of decimal digits.
lexDigits :: ReadS String
lexDigits :: ReadS String
lexDigits = forall a. ReadP a -> ReadS a
readP_to_S ((Char -> Bool) -> ReadP String
P.munch1 Char -> Bool
isDigit)

------------------------------------------------------------------------
-- utility parsers

lexP :: ReadPrec L.Lexeme
-- ^ Parse a single lexeme
lexP :: ReadPrec Lexeme
lexP = forall a. ReadP a -> ReadPrec a
lift ReadP Lexeme
L.lex

expectP :: L.Lexeme -> ReadPrec ()
expectP :: Lexeme -> ReadPrec ()
expectP Lexeme
lexeme = forall a. ReadP a -> ReadPrec a
lift (Lexeme -> ReadP ()
L.expect Lexeme
lexeme)

expectCharP :: Char -> ReadPrec a -> ReadPrec a
expectCharP :: forall a. Char -> ReadPrec a -> ReadPrec a
expectCharP Char
c ReadPrec a
a = do
  Char
q <- ReadPrec Char
get
  if Char
q forall a. Eq a => a -> a -> Bool
== Char
c
    then ReadPrec a
a
    else forall a. ReadPrec a
pfail
{-# INLINE expectCharP #-}

skipSpacesThenP :: ReadPrec a -> ReadPrec a
skipSpacesThenP :: forall a. ReadPrec a -> ReadPrec a
skipSpacesThenP ReadPrec a
m =
  do String
s <- ReadPrec String
look
     String -> ReadPrec a
skip String
s
 where
   skip :: String -> ReadPrec a
skip (Char
c:String
s) | Char -> Bool
isSpace Char
c = ReadPrec Char
get forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> String -> ReadPrec a
skip String
s
   skip String
_ = ReadPrec a
m

paren :: ReadPrec a -> ReadPrec a
-- ^ @(paren p)@ parses \"(P0)\"
--      where @p@ parses \"P0\" in precedence context zero
paren :: forall a. ReadPrec a -> ReadPrec a
paren ReadPrec a
p = forall a. ReadPrec a -> ReadPrec a
skipSpacesThenP (forall a. ReadPrec a -> ReadPrec a
paren' ReadPrec a
p)

paren' :: ReadPrec a -> ReadPrec a
paren' :: forall a. ReadPrec a -> ReadPrec a
paren' ReadPrec a
p = forall a. Char -> ReadPrec a -> ReadPrec a
expectCharP Char
'(' forall a b. (a -> b) -> a -> b
$ forall a. ReadPrec a -> ReadPrec a
reset ReadPrec a
p forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \a
x ->
              forall a. ReadPrec a -> ReadPrec a
skipSpacesThenP (forall a. Char -> ReadPrec a -> ReadPrec a
expectCharP Char
')' (forall (f :: * -> *) a. Applicative f => a -> f a
pure a
x))

parens :: ReadPrec a -> ReadPrec a
-- ^ @(parens p)@ parses \"P\", \"(P0)\", \"((P0))\", etc,
--      where @p@ parses \"P\"  in the current precedence context
--          and parses \"P0\" in precedence context zero
parens :: forall a. ReadPrec a -> ReadPrec a
parens ReadPrec a
p = ReadPrec a
optional
  where
    optional :: ReadPrec a
optional = forall a. ReadPrec a -> ReadPrec a
skipSpacesThenP (ReadPrec a
p forall a. ReadPrec a -> ReadPrec a -> ReadPrec a
+++ ReadPrec a
mandatory)
    mandatory :: ReadPrec a
mandatory = forall a. ReadPrec a -> ReadPrec a
paren' ReadPrec a
optional

list :: ReadPrec a -> ReadPrec [a]
-- ^ @(list p)@ parses a list of things parsed by @p@,
-- using the usual square-bracket syntax.
list :: forall a. ReadPrec a -> ReadPrec [a]
list ReadPrec a
readx =
  forall a. ReadPrec a -> ReadPrec a
parens
  ( do Lexeme -> ReadPrec ()
expectP (String -> Lexeme
L.Punc String
"[")
       (Bool -> ReadPrec [a]
listRest Bool
False forall a. ReadPrec a -> ReadPrec a -> ReadPrec a
+++ ReadPrec [a]
listNext)
  )
 where
  listRest :: Bool -> ReadPrec [a]
listRest Bool
started =
    do L.Punc String
c <- ReadPrec Lexeme
lexP
       case String
c of
         String
"]"           -> forall (m :: * -> *) a. Monad m => a -> m a
return []
         String
"," | Bool
started -> ReadPrec [a]
listNext
         String
_             -> forall a. ReadPrec a
pfail

  listNext :: ReadPrec [a]
listNext =
    do a
x  <- forall a. ReadPrec a -> ReadPrec a
reset ReadPrec a
readx
       [a]
xs <- Bool -> ReadPrec [a]
listRest Bool
True
       forall (m :: * -> *) a. Monad m => a -> m a
return (a
xforall a. a -> [a] -> [a]
:[a]
xs)

choose :: [(String, ReadPrec a)] -> ReadPrec a
-- ^ Parse the specified lexeme and continue as specified.
-- Esp useful for nullary constructors; e.g.
--    @choose [(\"A\", return A), (\"B\", return B)]@
-- We match both Ident and Symbol because the constructor
-- might be an operator eg @(:~:)@
choose :: forall a. [(String, ReadPrec a)] -> ReadPrec a
choose [(String, ReadPrec a)]
sps = forall a b. (a -> b -> b) -> b -> [a] -> b
foldr (forall a. ReadPrec a -> ReadPrec a -> ReadPrec a
(+++) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall {b}. (String, ReadPrec b) -> ReadPrec b
try_one) forall a. ReadPrec a
pfail [(String, ReadPrec a)]
sps
           where
             try_one :: (String, ReadPrec b) -> ReadPrec b
try_one (String
s,ReadPrec b
p) = do { Lexeme
token <- ReadPrec Lexeme
lexP ;
                                  case Lexeme
token of
                                    L.Ident String
s'  | String
sforall a. Eq a => a -> a -> Bool
==String
s' -> ReadPrec b
p
                                    L.Symbol String
s' | String
sforall a. Eq a => a -> a -> Bool
==String
s' -> ReadPrec b
p
                                    Lexeme
_other              -> forall a. ReadPrec a
pfail }

-- See Note [Why readField]

-- | 'Read' parser for a record field, of the form @fieldName=value@. The
-- @fieldName@ must be an alphanumeric identifier; for symbols (operator-style)
-- field names, e.g. @(#)@, use 'readSymField'). The second argument is a
-- parser for the field value.
readField :: String -> ReadPrec a -> ReadPrec a
readField :: forall a. String -> ReadPrec a -> ReadPrec a
readField String
fieldName ReadPrec a
readVal = do
        Lexeme -> ReadPrec ()
expectP (String -> Lexeme
L.Ident String
fieldName)
        Lexeme -> ReadPrec ()
expectP (String -> Lexeme
L.Punc String
"=")
        ReadPrec a
readVal
{-# NOINLINE readField #-}

-- See Note [Why readField]

-- | 'Read' parser for a record field, of the form @fieldName#=value@. That is,
-- an alphanumeric identifier @fieldName@ followed by the symbol @#@. The
-- second argument is a parser for the field value.
--
-- Note that 'readField' does not suffice for this purpose due to
-- <https://gitlab.haskell.org/ghc/ghc/issues/5041 #5041>.
readFieldHash :: String -> ReadPrec a -> ReadPrec a
readFieldHash :: forall a. String -> ReadPrec a -> ReadPrec a
readFieldHash String
fieldName ReadPrec a
readVal = do
        Lexeme -> ReadPrec ()
expectP (String -> Lexeme
L.Ident String
fieldName)
        Lexeme -> ReadPrec ()
expectP (String -> Lexeme
L.Symbol String
"#")
        Lexeme -> ReadPrec ()
expectP (String -> Lexeme
L.Punc String
"=")
        ReadPrec a
readVal
{-# NOINLINE readFieldHash #-}

-- See Note [Why readField]

-- | 'Read' parser for a symbol record field, of the form @(###)=value@ (where
-- @###@ is the field name). The field name must be a symbol (operator-style),
-- e.g. @(#)@. For regular (alphanumeric) field names, use 'readField'. The
-- second argument is a parser for the field value.
readSymField :: String -> ReadPrec a -> ReadPrec a
readSymField :: forall a. String -> ReadPrec a -> ReadPrec a
readSymField String
fieldName ReadPrec a
readVal = do
        Lexeme -> ReadPrec ()
expectP (String -> Lexeme
L.Punc String
"(")
        Lexeme -> ReadPrec ()
expectP (String -> Lexeme
L.Symbol String
fieldName)
        Lexeme -> ReadPrec ()
expectP (String -> Lexeme
L.Punc String
")")
        Lexeme -> ReadPrec ()
expectP (String -> Lexeme
L.Punc String
"=")
        ReadPrec a
readVal
{-# NOINLINE readSymField #-}


-- Note [Why readField]
--
-- Previously, the code for automatically deriving Read instance (in
-- typecheck/GHC.Tc.Deriv.Generate.hs) would generate inline code for parsing fields;
-- this, however, turned out to produce massive amounts of intermediate code,
-- and produced a considerable performance hit in the code generator.
-- Since Read instances are not generally supposed to be performance critical,
-- the readField and readSymField functions have been factored out, and the
-- code generator now just generates calls rather than manually inlining the
-- parsers. For large record types (e.g. 500 fields), this produces a
-- significant performance boost.
--
-- See also #14364.


--------------------------------------------------------------
-- Simple instances of Read
--------------------------------------------------------------

-- | @since 2.01
deriving instance Read GeneralCategory

-- | @since 2.01
instance Read Char where
  readPrec :: ReadPrec Char
readPrec =
    forall a. ReadPrec a -> ReadPrec a
parens
    ( do L.Char Char
c <- ReadPrec Lexeme
lexP
         forall (m :: * -> *) a. Monad m => a -> m a
return Char
c
    )

  readListPrec :: ReadPrec String
readListPrec =
    forall a. ReadPrec a -> ReadPrec a
parens
    ( do L.String String
s <- ReadPrec Lexeme
lexP     -- Looks for "foo"
         forall (m :: * -> *) a. Monad m => a -> m a
return String
s
     forall a. ReadPrec a -> ReadPrec a -> ReadPrec a
+++
      forall a. Read a => ReadPrec [a]
readListPrecDefault       -- Looks for ['f','o','o']
    )                           -- (more generous than H2010 spec)

  readList :: ReadS String
readList = forall a. Read a => ReadS [a]
readListDefault

-- | @since 2.01
instance Read Bool where
  readPrec :: ReadPrec Bool
readPrec =
    forall a. ReadPrec a -> ReadPrec a
parens
    ( do L.Ident String
s <- ReadPrec Lexeme
lexP
         case String
s of
           String
"True"  -> forall (m :: * -> *) a. Monad m => a -> m a
return Bool
True
           String
"False" -> forall (m :: * -> *) a. Monad m => a -> m a
return Bool
False
           String
_       -> forall a. ReadPrec a
pfail
    )

  readListPrec :: ReadPrec [Bool]
readListPrec = forall a. Read a => ReadPrec [a]
readListPrecDefault
  readList :: ReadS [Bool]
readList     = forall a. Read a => ReadS [a]
readListDefault

-- | @since 2.01
instance Read Ordering where
  readPrec :: ReadPrec Ordering
readPrec =
    forall a. ReadPrec a -> ReadPrec a
parens
    ( do L.Ident String
s <- ReadPrec Lexeme
lexP
         case String
s of
           String
"LT" -> forall (m :: * -> *) a. Monad m => a -> m a
return Ordering
LT
           String
"EQ" -> forall (m :: * -> *) a. Monad m => a -> m a
return Ordering
EQ
           String
"GT" -> forall (m :: * -> *) a. Monad m => a -> m a
return Ordering
GT
           String
_    -> forall a. ReadPrec a
pfail
    )

  readListPrec :: ReadPrec [Ordering]
readListPrec = forall a. Read a => ReadPrec [a]
readListPrecDefault
  readList :: ReadS [Ordering]
readList     = forall a. Read a => ReadS [a]
readListDefault

-- | @since 4.11.0.0
deriving instance Read a => Read (NonEmpty a)

--------------------------------------------------------------
-- Structure instances of Read: Maybe, List etc
--------------------------------------------------------------

{-
For structured instances of Read we start using the precedences.  The
idea is then that 'parens (prec k p)' will fail immediately when trying
to parse it in a context with a higher precedence level than k. But if
there is one parenthesis parsed, then the required precedence level
drops to 0 again, and parsing inside p may succeed.

'appPrec' is just the precedence level of function application.  So,
if we are parsing function application, we'd better require the
precedence level to be at least 'appPrec'. Otherwise, we have to put
parentheses around it.

'step' is used to increase the precedence levels inside a
parser, and can be used to express left- or right- associativity. For
example, % is defined to be left associative, so we only increase
precedence on the right hand side.

Note how step is used in for example the Maybe parser to increase the
precedence beyond appPrec, so that basically only literals and
parenthesis-like objects such as (...) and [...] can be an argument to
'Just'.
-}

-- | @since 2.01
instance Read a => Read (Maybe a) where
  readPrec :: ReadPrec (Maybe a)
readPrec =
    forall a. ReadPrec a -> ReadPrec a
parens
    (do Lexeme -> ReadPrec ()
expectP (String -> Lexeme
L.Ident String
"Nothing")
        forall (m :: * -> *) a. Monad m => a -> m a
return forall a. Maybe a
Nothing
     forall a. ReadPrec a -> ReadPrec a -> ReadPrec a
+++
     forall a. Int -> ReadPrec a -> ReadPrec a
prec Int
appPrec (
        do Lexeme -> ReadPrec ()
expectP (String -> Lexeme
L.Ident String
"Just")
           a
x <- forall a. ReadPrec a -> ReadPrec a
step forall a. Read a => ReadPrec a
readPrec
           forall (m :: * -> *) a. Monad m => a -> m a
return (forall a. a -> Maybe a
Just a
x))
    )

  readListPrec :: ReadPrec [Maybe a]
readListPrec = forall a. Read a => ReadPrec [a]
readListPrecDefault
  readList :: ReadS [Maybe a]
readList     = forall a. Read a => ReadS [a]
readListDefault

-- | @since 2.01
instance Read a => Read [a] where
  {-# SPECIALISE instance Read [String] #-}
  {-# SPECIALISE instance Read [Char] #-}
  {-# SPECIALISE instance Read [Int] #-}
  readPrec :: ReadPrec [a]
readPrec     = forall a. Read a => ReadPrec [a]
readListPrec
  readListPrec :: ReadPrec [[a]]
readListPrec = forall a. Read a => ReadPrec [a]
readListPrecDefault
  readList :: ReadS [[a]]
readList     = forall a. Read a => ReadS [a]
readListDefault

-- | @since 2.01
instance  (Ix a, Read a, Read b) => Read (Array a b)  where
    readPrec :: ReadPrec (Array a b)
readPrec = forall a. ReadPrec a -> ReadPrec a
parens forall a b. (a -> b) -> a -> b
$ forall a. Int -> ReadPrec a -> ReadPrec a
prec Int
appPrec forall a b. (a -> b) -> a -> b
$
               do Lexeme -> ReadPrec ()
expectP (String -> Lexeme
L.Ident String
"array")
                  (a, a)
theBounds <- forall a. ReadPrec a -> ReadPrec a
step forall a. Read a => ReadPrec a
readPrec
                  [(a, b)]
vals   <- forall a. ReadPrec a -> ReadPrec a
step forall a. Read a => ReadPrec a
readPrec
                  forall (m :: * -> *) a. Monad m => a -> m a
return (forall i e. Ix i => (i, i) -> [(i, e)] -> Array i e
array (a, a)
theBounds [(a, b)]
vals)

    readListPrec :: ReadPrec [Array a b]
readListPrec = forall a. Read a => ReadPrec [a]
readListPrecDefault
    readList :: ReadS [Array a b]
readList     = forall a. Read a => ReadS [a]
readListDefault

-- | @since 2.01
instance Read L.Lexeme where
  readPrec :: ReadPrec Lexeme
readPrec     = ReadPrec Lexeme
lexP
  readListPrec :: ReadPrec [Lexeme]
readListPrec = forall a. Read a => ReadPrec [a]
readListPrecDefault
  readList :: ReadS [Lexeme]
readList     = forall a. Read a => ReadS [a]
readListDefault

--------------------------------------------------------------
-- Numeric instances of Read
--------------------------------------------------------------

readNumber :: Num a => (L.Lexeme -> ReadPrec a) -> ReadPrec a
-- Read a signed number
readNumber :: forall a. Num a => (Lexeme -> ReadPrec a) -> ReadPrec a
readNumber Lexeme -> ReadPrec a
convert =
  forall a. ReadPrec a -> ReadPrec a
parens
  ( do Lexeme
x <- ReadPrec Lexeme
lexP
       case Lexeme
x of
         L.Symbol String
"-" -> do Lexeme
y <- ReadPrec Lexeme
lexP
                            a
n <- Lexeme -> ReadPrec a
convert Lexeme
y
                            forall (m :: * -> *) a. Monad m => a -> m a
return (forall a. Num a => a -> a
negate a
n)

         Lexeme
_   -> Lexeme -> ReadPrec a
convert Lexeme
x
  )


convertInt :: Num a => L.Lexeme -> ReadPrec a
convertInt :: forall a. Num a => Lexeme -> ReadPrec a
convertInt (L.Number Number
n)
 | Just Integer
i <- Number -> Maybe Integer
L.numberToInteger Number
n = forall (m :: * -> *) a. Monad m => a -> m a
return (forall a. Num a => Integer -> a
fromInteger Integer
i)
convertInt Lexeme
_ = forall a. ReadPrec a
pfail

convertFrac :: forall a . RealFloat a => L.Lexeme -> ReadPrec a
convertFrac :: forall a. RealFloat a => Lexeme -> ReadPrec a
convertFrac (L.Ident String
"NaN")      = forall (m :: * -> *) a. Monad m => a -> m a
return (a
0 forall a. Fractional a => a -> a -> a
/ a
0)
convertFrac (L.Ident String
"Infinity") = forall (m :: * -> *) a. Monad m => a -> m a
return (a
1 forall a. Fractional a => a -> a -> a
/ a
0)
convertFrac (L.Number Number
n) = let resRange :: (Int, Int)
resRange = forall a. RealFloat a => a -> (Int, Int)
floatRange (forall a. HasCallStack => a
undefined :: a)
                           in case (Int, Int) -> Number -> Maybe Rational
L.numberToRangedRational (Int, Int)
resRange Number
n of
                              Maybe Rational
Nothing -> forall (m :: * -> *) a. Monad m => a -> m a
return (a
1 forall a. Fractional a => a -> a -> a
/ a
0)
                              Just Rational
rat -> forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall a. Fractional a => Rational -> a
fromRational Rational
rat
convertFrac Lexeme
_            = forall a. ReadPrec a
pfail

-- | @since 2.01
instance Read Int where
  readPrec :: ReadPrec Int
readPrec     = forall a. Num a => (Lexeme -> ReadPrec a) -> ReadPrec a
readNumber forall a. Num a => Lexeme -> ReadPrec a
convertInt
  readListPrec :: ReadPrec [Int]
readListPrec = forall a. Read a => ReadPrec [a]
readListPrecDefault
  readList :: ReadS [Int]
readList     = forall a. Read a => ReadS [a]
readListDefault

-- | @since 4.5.0.0
instance Read Word where
    readsPrec :: Int -> ReadS Word
readsPrec Int
p String
s = [(forall a. Num a => Integer -> a
fromInteger Integer
x, String
r) | (Integer
x, String
r) <- forall a. Read a => Int -> ReadS a
readsPrec Int
p String
s]

-- | @since 2.01
instance Read Word8 where
    readsPrec :: Int -> ReadS Word8
readsPrec Int
p String
s = [(forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int
x::Int), String
r) | (Int
x, String
r) <- forall a. Read a => Int -> ReadS a
readsPrec Int
p String
s]

-- | @since 2.01
instance Read Word16 where
    readsPrec :: Int -> ReadS Word16
readsPrec Int
p String
s = [(forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int
x::Int), String
r) | (Int
x, String
r) <- forall a. Read a => Int -> ReadS a
readsPrec Int
p String
s]

-- | @since 2.01
instance Read Word32 where
#if WORD_SIZE_IN_BITS < 33
    readsPrec p s = [(fromInteger x, r) | (x, r) <- readsPrec p s]
#else
    readsPrec :: Int -> ReadS Word32
readsPrec Int
p String
s = [(forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int
x::Int), String
r) | (Int
x, String
r) <- forall a. Read a => Int -> ReadS a
readsPrec Int
p String
s]
#endif

-- | @since 2.01
instance Read Word64 where
    readsPrec :: Int -> ReadS Word64
readsPrec Int
p String
s = [(forall a. Num a => Integer -> a
fromInteger Integer
x, String
r) | (Integer
x, String
r) <- forall a. Read a => Int -> ReadS a
readsPrec Int
p String
s]

-- | @since 2.01
instance Read Integer where
  readPrec :: ReadPrec Integer
readPrec     = forall a. Num a => (Lexeme -> ReadPrec a) -> ReadPrec a
readNumber forall a. Num a => Lexeme -> ReadPrec a
convertInt
  readListPrec :: ReadPrec [Integer]
readListPrec = forall a. Read a => ReadPrec [a]
readListPrecDefault
  readList :: ReadS [Integer]
readList     = forall a. Read a => ReadS [a]
readListDefault


-- | @since 4.8.0.0
instance Read Natural where
  readsPrec :: Int -> ReadS Natural
readsPrec Int
d = forall a b. (a -> b) -> [a] -> [b]
map (\(Integer
n, String
s) -> (forall a. Num a => Integer -> a
fromInteger Integer
n, String
s))
                  forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. (a -> Bool) -> [a] -> [a]
filter ((forall a. Ord a => a -> a -> Bool
>= Integer
0) forall b c a. (b -> c) -> (a -> b) -> a -> c
. (\(Integer
x,String
_)->Integer
x)) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Read a => Int -> ReadS a
readsPrec Int
d

-- | @since 2.01
instance Read Float where
  readPrec :: ReadPrec Float
readPrec     = forall a. Num a => (Lexeme -> ReadPrec a) -> ReadPrec a
readNumber forall a. RealFloat a => Lexeme -> ReadPrec a
convertFrac
  readListPrec :: ReadPrec [Float]
readListPrec = forall a. Read a => ReadPrec [a]
readListPrecDefault
  readList :: ReadS [Float]
readList     = forall a. Read a => ReadS [a]
readListDefault

-- | @since 2.01
instance Read Double where
  readPrec :: ReadPrec Double
readPrec     = forall a. Num a => (Lexeme -> ReadPrec a) -> ReadPrec a
readNumber forall a. RealFloat a => Lexeme -> ReadPrec a
convertFrac
  readListPrec :: ReadPrec [Double]
readListPrec = forall a. Read a => ReadPrec [a]
readListPrecDefault
  readList :: ReadS [Double]
readList     = forall a. Read a => ReadS [a]
readListDefault

-- | @since 2.01
instance (Integral a, Read a) => Read (Ratio a) where
  readPrec :: ReadPrec (Ratio a)
readPrec =
    forall a. ReadPrec a -> ReadPrec a
parens
    ( forall a. Int -> ReadPrec a -> ReadPrec a
prec Int
ratioPrec
      ( do a
x <- forall a. ReadPrec a -> ReadPrec a
step forall a. Read a => ReadPrec a
readPrec
           Lexeme -> ReadPrec ()
expectP (String -> Lexeme
L.Symbol String
"%")
           a
y <- forall a. ReadPrec a -> ReadPrec a
step forall a. Read a => ReadPrec a
readPrec
           forall (m :: * -> *) a. Monad m => a -> m a
return (a
x forall a. Integral a => a -> a -> Ratio a
% a
y)
      )
    )

  readListPrec :: ReadPrec [Ratio a]
readListPrec = forall a. Read a => ReadPrec [a]
readListPrecDefault
  readList :: ReadS [Ratio a]
readList     = forall a. Read a => ReadS [a]
readListDefault


------------------------------------------------------------------------
-- Tuple instances of Read, up to size 15
------------------------------------------------------------------------

-- | @since 2.01
instance Read () where
  readPrec :: ReadPrec ()
readPrec =
    forall a. ReadPrec a -> ReadPrec a
parens
    ( forall a. ReadPrec a -> ReadPrec a
paren
      ( forall (m :: * -> *) a. Monad m => a -> m a
return ()
      )
    )

  readListPrec :: ReadPrec [()]
readListPrec = forall a. Read a => ReadPrec [a]
readListPrecDefault
  readList :: ReadS [()]
readList     = forall a. Read a => ReadS [a]
readListDefault

-- | @since 4.15
deriving instance Read a => Read (Solo a)

-- | @since 2.01
instance (Read a, Read b) => Read (a,b) where
  readPrec :: ReadPrec (a, b)
readPrec = forall a. ReadPrec a -> ReadPrec a
wrap_tup forall a b. (Read a, Read b) => ReadPrec (a, b)
read_tup2
  readListPrec :: ReadPrec [(a, b)]
readListPrec = forall a. Read a => ReadPrec [a]
readListPrecDefault
  readList :: ReadS [(a, b)]
readList     = forall a. Read a => ReadS [a]
readListDefault

wrap_tup :: ReadPrec a -> ReadPrec a
wrap_tup :: forall a. ReadPrec a -> ReadPrec a
wrap_tup ReadPrec a
p = forall a. ReadPrec a -> ReadPrec a
parens (forall a. ReadPrec a -> ReadPrec a
paren ReadPrec a
p)

read_comma :: ReadPrec ()
read_comma :: ReadPrec ()
read_comma = Lexeme -> ReadPrec ()
expectP (String -> Lexeme
L.Punc String
",")

read_tup2 :: (Read a, Read b) => ReadPrec (a,b)
-- Reads "a , b"  no parens!
read_tup2 :: forall a b. (Read a, Read b) => ReadPrec (a, b)
read_tup2 = do a
x <- forall a. Read a => ReadPrec a
readPrec
               ReadPrec ()
read_comma
               b
y <- forall a. Read a => ReadPrec a
readPrec
               forall (m :: * -> *) a. Monad m => a -> m a
return (a
x,b
y)

read_tup4 :: (Read a, Read b, Read c, Read d) => ReadPrec (a,b,c,d)
read_tup4 :: forall a b c d.
(Read a, Read b, Read c, Read d) =>
ReadPrec (a, b, c, d)
read_tup4 = do  (a
a,b
b) <- forall a b. (Read a, Read b) => ReadPrec (a, b)
read_tup2
                ReadPrec ()
read_comma
                (c
c,d
d) <- forall a b. (Read a, Read b) => ReadPrec (a, b)
read_tup2
                forall (m :: * -> *) a. Monad m => a -> m a
return (a
a,b
b,c
c,d
d)


read_tup8 :: (Read a, Read b, Read c, Read d, Read e, Read f, Read g, Read h)
          => ReadPrec (a,b,c,d,e,f,g,h)
read_tup8 :: forall a b c d e f g h.
(Read a, Read b, Read c, Read d, Read e, Read f, Read g, Read h) =>
ReadPrec (a, b, c, d, e, f, g, h)
read_tup8 = do  (a
a,b
b,c
c,d
d) <- forall a b c d.
(Read a, Read b, Read c, Read d) =>
ReadPrec (a, b, c, d)
read_tup4
                ReadPrec ()
read_comma
                (e
e,f
f,g
g,h
h) <- forall a b c d.
(Read a, Read b, Read c, Read d) =>
ReadPrec (a, b, c, d)
read_tup4
                forall (m :: * -> *) a. Monad m => a -> m a
return (a
a,b
b,c
c,d
d,e
e,f
f,g
g,h
h)


-- | @since 2.01
instance (Read a, Read b, Read c) => Read (a, b, c) where
  readPrec :: ReadPrec (a, b, c)
readPrec = forall a. ReadPrec a -> ReadPrec a
wrap_tup (do { (a
a,b
b) <- forall a b. (Read a, Read b) => ReadPrec (a, b)
read_tup2; ReadPrec ()
read_comma
                          ; c
c <- forall a. Read a => ReadPrec a
readPrec
                          ; forall (m :: * -> *) a. Monad m => a -> m a
return (a
a,b
b,c
c) })
  readListPrec :: ReadPrec [(a, b, c)]
readListPrec = forall a. Read a => ReadPrec [a]
readListPrecDefault
  readList :: ReadS [(a, b, c)]
readList     = forall a. Read a => ReadS [a]
readListDefault

-- | @since 2.01
instance (Read a, Read b, Read c, Read d) => Read (a, b, c, d) where
  readPrec :: ReadPrec (a, b, c, d)
readPrec = forall a. ReadPrec a -> ReadPrec a
wrap_tup forall a b c d.
(Read a, Read b, Read c, Read d) =>
ReadPrec (a, b, c, d)
read_tup4
  readListPrec :: ReadPrec [(a, b, c, d)]
readListPrec = forall a. Read a => ReadPrec [a]
readListPrecDefault
  readList :: ReadS [(a, b, c, d)]
readList     = forall a. Read a => ReadS [a]
readListDefault

-- | @since 2.01
instance (Read a, Read b, Read c, Read d, Read e) => Read (a, b, c, d, e) where
  readPrec :: ReadPrec (a, b, c, d, e)
readPrec = forall a. ReadPrec a -> ReadPrec a
wrap_tup (do { (a
a,b
b,c
c,d
d) <- forall a b c d.
(Read a, Read b, Read c, Read d) =>
ReadPrec (a, b, c, d)
read_tup4; ReadPrec ()
read_comma
                          ; e
e <- forall a. Read a => ReadPrec a
readPrec
                          ; forall (m :: * -> *) a. Monad m => a -> m a
return (a
a,b
b,c
c,d
d,e
e) })
  readListPrec :: ReadPrec [(a, b, c, d, e)]
readListPrec = forall a. Read a => ReadPrec [a]
readListPrecDefault
  readList :: ReadS [(a, b, c, d, e)]
readList     = forall a. Read a => ReadS [a]
readListDefault

-- | @since 2.01
instance (Read a, Read b, Read c, Read d, Read e, Read f)
        => Read (a, b, c, d, e, f) where
  readPrec :: ReadPrec (a, b, c, d, e, f)
readPrec = forall a. ReadPrec a -> ReadPrec a
wrap_tup (do { (a
a,b
b,c
c,d
d) <- forall a b c d.
(Read a, Read b, Read c, Read d) =>
ReadPrec (a, b, c, d)
read_tup4; ReadPrec ()
read_comma
                          ; (e
e,f
f) <- forall a b. (Read a, Read b) => ReadPrec (a, b)
read_tup2
                          ; forall (m :: * -> *) a. Monad m => a -> m a
return (a
a,b
b,c
c,d
d,e
e,f
f) })
  readListPrec :: ReadPrec [(a, b, c, d, e, f)]
readListPrec = forall a. Read a => ReadPrec [a]
readListPrecDefault
  readList :: ReadS [(a, b, c, d, e, f)]
readList     = forall a. Read a => ReadS [a]
readListDefault

-- | @since 2.01
instance (Read a, Read b, Read c, Read d, Read e, Read f, Read g)
        => Read (a, b, c, d, e, f, g) where
  readPrec :: ReadPrec (a, b, c, d, e, f, g)
readPrec = forall a. ReadPrec a -> ReadPrec a
wrap_tup (do { (a
a,b
b,c
c,d
d) <- forall a b c d.
(Read a, Read b, Read c, Read d) =>
ReadPrec (a, b, c, d)
read_tup4; ReadPrec ()
read_comma
                          ; (e
e,f
f) <- forall a b. (Read a, Read b) => ReadPrec (a, b)
read_tup2; ReadPrec ()
read_comma
                          ; g
g <- forall a. Read a => ReadPrec a
readPrec
                          ; forall (m :: * -> *) a. Monad m => a -> m a
return (a
a,b
b,c
c,d
d,e
e,f
f,g
g) })
  readListPrec :: ReadPrec [(a, b, c, d, e, f, g)]
readListPrec = forall a. Read a => ReadPrec [a]
readListPrecDefault
  readList :: ReadS [(a, b, c, d, e, f, g)]
readList     = forall a. Read a => ReadS [a]
readListDefault

-- | @since 2.01
instance (Read a, Read b, Read c, Read d, Read e, Read f, Read g, Read h)
        => Read (a, b, c, d, e, f, g, h) where
  readPrec :: ReadPrec (a, b, c, d, e, f, g, h)
readPrec     = forall a. ReadPrec a -> ReadPrec a
wrap_tup forall a b c d e f g h.
(Read a, Read b, Read c, Read d, Read e, Read f, Read g, Read h) =>
ReadPrec (a, b, c, d, e, f, g, h)
read_tup8
  readListPrec :: ReadPrec [(a, b, c, d, e, f, g, h)]
readListPrec = forall a. Read a => ReadPrec [a]
readListPrecDefault
  readList :: ReadS [(a, b, c, d, e, f, g, h)]
readList     = forall a. Read a => ReadS [a]
readListDefault

-- | @since 2.01
instance (Read a, Read b, Read c, Read d, Read e, Read f, Read g, Read h,
          Read i)
        => Read (a, b, c, d, e, f, g, h, i) where
  readPrec :: ReadPrec (a, b, c, d, e, f, g, h, i)
readPrec = forall a. ReadPrec a -> ReadPrec a
wrap_tup (do { (a
a,b
b,c
c,d
d,e
e,f
f,g
g,h
h) <- forall a b c d e f g h.
(Read a, Read b, Read c, Read d, Read e, Read f, Read g, Read h) =>
ReadPrec (a, b, c, d, e, f, g, h)
read_tup8; ReadPrec ()
read_comma
                          ; i
i <- forall a. Read a => ReadPrec a
readPrec
                          ; forall (m :: * -> *) a. Monad m => a -> m a
return (a
a,b
b,c
c,d
d,e
e,f
f,g
g,h
h,i
i) })
  readListPrec :: ReadPrec [(a, b, c, d, e, f, g, h, i)]
readListPrec = forall a. Read a => ReadPrec [a]
readListPrecDefault
  readList :: ReadS [(a, b, c, d, e, f, g, h, i)]
readList     = forall a. Read a => ReadS [a]
readListDefault

-- | @since 2.01
instance (Read a, Read b, Read c, Read d, Read e, Read f, Read g, Read h,
          Read i, Read j)
        => Read (a, b, c, d, e, f, g, h, i, j) where
  readPrec :: ReadPrec (a, b, c, d, e, f, g, h, i, j)
readPrec = forall a. ReadPrec a -> ReadPrec a
wrap_tup (do { (a
a,b
b,c
c,d
d,e
e,f
f,g
g,h
h) <- forall a b c d e f g h.
(Read a, Read b, Read c, Read d, Read e, Read f, Read g, Read h) =>
ReadPrec (a, b, c, d, e, f, g, h)
read_tup8; ReadPrec ()
read_comma
                          ; (i
i,j
j) <- forall a b. (Read a, Read b) => ReadPrec (a, b)
read_tup2
                          ; forall (m :: * -> *) a. Monad m => a -> m a
return (a
a,b
b,c
c,d
d,e
e,f
f,g
g,h
h,i
i,j
j) })
  readListPrec :: ReadPrec [(a, b, c, d, e, f, g, h, i, j)]
readListPrec = forall a. Read a => ReadPrec [a]
readListPrecDefault
  readList :: ReadS [(a, b, c, d, e, f, g, h, i, j)]
readList     = forall a. Read a => ReadS [a]
readListDefault

-- | @since 2.01
instance (Read a, Read b, Read c, Read d, Read e, Read f, Read g, Read h,
          Read i, Read j, Read k)
        => Read (a, b, c, d, e, f, g, h, i, j, k) where
  readPrec :: ReadPrec (a, b, c, d, e, f, g, h, i, j, k)
readPrec = forall a. ReadPrec a -> ReadPrec a
wrap_tup (do { (a
a,b
b,c
c,d
d,e
e,f
f,g
g,h
h) <- forall a b c d e f g h.
(Read a, Read b, Read c, Read d, Read e, Read f, Read g, Read h) =>
ReadPrec (a, b, c, d, e, f, g, h)
read_tup8; ReadPrec ()
read_comma
                          ; (i
i,j
j) <- forall a b. (Read a, Read b) => ReadPrec (a, b)
read_tup2; ReadPrec ()
read_comma
                          ; k
k <- forall a. Read a => ReadPrec a
readPrec
                          ; forall (m :: * -> *) a. Monad m => a -> m a
return (a
a,b
b,c
c,d
d,e
e,f
f,g
g,h
h,i
i,j
j,k
k) })
  readListPrec :: ReadPrec [(a, b, c, d, e, f, g, h, i, j, k)]
readListPrec = forall a. Read a => ReadPrec [a]
readListPrecDefault
  readList :: ReadS [(a, b, c, d, e, f, g, h, i, j, k)]
readList     = forall a. Read a => ReadS [a]
readListDefault

-- | @since 2.01
instance (Read a, Read b, Read c, Read d, Read e, Read f, Read g, Read h,
          Read i, Read j, Read k, Read l)
        => Read (a, b, c, d, e, f, g, h, i, j, k, l) where
  readPrec :: ReadPrec (a, b, c, d, e, f, g, h, i, j, k, l)
readPrec = forall a. ReadPrec a -> ReadPrec a
wrap_tup (do { (a
a,b
b,c
c,d
d,e
e,f
f,g
g,h
h) <- forall a b c d e f g h.
(Read a, Read b, Read c, Read d, Read e, Read f, Read g, Read h) =>
ReadPrec (a, b, c, d, e, f, g, h)
read_tup8; ReadPrec ()
read_comma
                          ; (i
i,j
j,k
k,l
l) <- forall a b c d.
(Read a, Read b, Read c, Read d) =>
ReadPrec (a, b, c, d)
read_tup4
                          ; forall (m :: * -> *) a. Monad m => a -> m a
return (a
a,b
b,c
c,d
d,e
e,f
f,g
g,h
h,i
i,j
j,k
k,l
l) })
  readListPrec :: ReadPrec [(a, b, c, d, e, f, g, h, i, j, k, l)]
readListPrec = forall a. Read a => ReadPrec [a]
readListPrecDefault
  readList :: ReadS [(a, b, c, d, e, f, g, h, i, j, k, l)]
readList     = forall a. Read a => ReadS [a]
readListDefault

-- | @since 2.01
instance (Read a, Read b, Read c, Read d, Read e, Read f, Read g, Read h,
          Read i, Read j, Read k, Read l, Read m)
        => Read (a, b, c, d, e, f, g, h, i, j, k, l, m) where
  readPrec :: ReadPrec (a, b, c, d, e, f, g, h, i, j, k, l, m)
readPrec = forall a. ReadPrec a -> ReadPrec a
wrap_tup (do { (a
a,b
b,c
c,d
d,e
e,f
f,g
g,h
h) <- forall a b c d e f g h.
(Read a, Read b, Read c, Read d, Read e, Read f, Read g, Read h) =>
ReadPrec (a, b, c, d, e, f, g, h)
read_tup8; ReadPrec ()
read_comma
                          ; (i
i,j
j,k
k,l
l) <- forall a b c d.
(Read a, Read b, Read c, Read d) =>
ReadPrec (a, b, c, d)
read_tup4; ReadPrec ()
read_comma
                          ; m
m <- forall a. Read a => ReadPrec a
readPrec
                          ; forall (m :: * -> *) a. Monad m => a -> m a
return (a
a,b
b,c
c,d
d,e
e,f
f,g
g,h
h,i
i,j
j,k
k,l
l,m
m) })
  readListPrec :: ReadPrec [(a, b, c, d, e, f, g, h, i, j, k, l, m)]
readListPrec = forall a. Read a => ReadPrec [a]
readListPrecDefault
  readList :: ReadS [(a, b, c, d, e, f, g, h, i, j, k, l, m)]
readList     = forall a. Read a => ReadS [a]
readListDefault

-- | @since 2.01
instance (Read a, Read b, Read c, Read d, Read e, Read f, Read g, Read h,
          Read i, Read j, Read k, Read l, Read m, Read n)
        => Read (a, b, c, d, e, f, g, h, i, j, k, l, m, n) where
  readPrec :: ReadPrec (a, b, c, d, e, f, g, h, i, j, k, l, m, n)
readPrec = forall a. ReadPrec a -> ReadPrec a
wrap_tup (do { (a
a,b
b,c
c,d
d,e
e,f
f,g
g,h
h) <- forall a b c d e f g h.
(Read a, Read b, Read c, Read d, Read e, Read f, Read g, Read h) =>
ReadPrec (a, b, c, d, e, f, g, h)
read_tup8; ReadPrec ()
read_comma
                          ; (i
i,j
j,k
k,l
l) <- forall a b c d.
(Read a, Read b, Read c, Read d) =>
ReadPrec (a, b, c, d)
read_tup4; ReadPrec ()
read_comma
                          ; (m
m,n
n) <- forall a b. (Read a, Read b) => ReadPrec (a, b)
read_tup2
                          ; forall (m :: * -> *) a. Monad m => a -> m a
return (a
a,b
b,c
c,d
d,e
e,f
f,g
g,h
h,i
i,j
j,k
k,l
l,m
m,n
n) })
  readListPrec :: ReadPrec [(a, b, c, d, e, f, g, h, i, j, k, l, m, n)]
readListPrec = forall a. Read a => ReadPrec [a]
readListPrecDefault
  readList :: ReadS [(a, b, c, d, e, f, g, h, i, j, k, l, m, n)]
readList     = forall a. Read a => ReadS [a]
readListDefault

-- | @since 2.01
instance (Read a, Read b, Read c, Read d, Read e, Read f, Read g, Read h,
          Read i, Read j, Read k, Read l, Read m, Read n, Read o)
        => Read (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) where
  readPrec :: ReadPrec (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o)
readPrec = forall a. ReadPrec a -> ReadPrec a
wrap_tup (do { (a
a,b
b,c
c,d
d,e
e,f
f,g
g,h
h) <- forall a b c d e f g h.
(Read a, Read b, Read c, Read d, Read e, Read f, Read g, Read h) =>
ReadPrec (a, b, c, d, e, f, g, h)
read_tup8; ReadPrec ()
read_comma
                          ; (i
i,j
j,k
k,l
l) <- forall a b c d.
(Read a, Read b, Read c, Read d) =>
ReadPrec (a, b, c, d)
read_tup4; ReadPrec ()
read_comma
                          ; (m
m,n
n) <- forall a b. (Read a, Read b) => ReadPrec (a, b)
read_tup2; ReadPrec ()
read_comma
                          ; o
o <- forall a. Read a => ReadPrec a
readPrec
                          ; forall (m :: * -> *) a. Monad m => a -> m a
return (a
a,b
b,c
c,d
d,e
e,f
f,g
g,h
h,i
i,j
j,k
k,l
l,m
m,n
n,o
o) })
  readListPrec :: ReadPrec [(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o)]
readListPrec = forall a. Read a => ReadPrec [a]
readListPrecDefault
  readList :: ReadS [(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o)]
readList     = forall a. Read a => ReadS [a]
readListDefault