HORIZON HASKELLDocslts/ghc-9.10.xc74966e2026-09-27Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · c74966e · 2026-09-27

Modulererebase-1.21.2Haskell2010

Text.Read

  • 4 types
  • 1 class
  • 25 values
classclass Read a where
#

Parsing of Strings, 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

Methods

  • readsPrec :: Int -> ReadS a

    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:

    That is, readsPrec parses the string produced by showsPrec, and delivers the value that showsPrec started with.

  • readList :: 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 are expected to use double quotes, rather than square brackets.

  • readPrec :: ReadPrec a

    Proposed replacement for readsPrec using new-style parsers (GHC only).

  • readListPrec :: 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.

Instances240Read, …
  • Read OptionsDefined in bifunctors-5.6.2 · Data.Bifunctor.TH
  • Read ByteStringDefined in bytestring-0.12.2.0 · Data.ByteString.Internal.Type
  • Read ByteStringDefined in bytestring-0.12.2.0 · Data.ByteString.Lazy.Internal
  • Read ShortByteStringDefined in bytestring-0.12.2.0 · Data.ByteString.Short.Internal
  • Read IntSetDefined in containers-0.7 · Data.IntSet.Internal
  • Read IntegerDefined in ghc-internal-9.1003.0 · GHC.Internal.Read
  • Read NaturalDefined in ghc-internal-9.1003.0 · GHC.Internal.Read
  • Read VoidDefined in ghc-internal-9.1003.0 · GHC.Internal.Read

    Reading a Void value is always a parse error, considering Void as a data type with no constructors.

  • Read ByteOrderDefined in ghc-internal-9.1003.0 · GHC.Internal.ByteOrder
  • Read AllDefined in ghc-internal-9.1003.0 · GHC.Internal.Data.Semigroup.Internal
  • Read AnyDefined in ghc-internal-9.1003.0 · GHC.Internal.Data.Semigroup.Internal
  • Read VersionDefined in ghc-internal-9.1003.0 · GHC.Internal.Data.Version
  • Read CBoolDefined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.C.Types
  • Read CCharDefined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.C.Types
  • Read CClockDefined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.C.Types
  • Read CDoubleDefined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.C.Types
  • Read CFloatDefined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.C.Types
  • Read CIntDefined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.C.Types
  • Read CIntMaxDefined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.C.Types
  • Read CIntPtrDefined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.C.Types
  • Read CLLongDefined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.C.Types
  • Read CLongDefined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.C.Types
  • Read CPtrdiffDefined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.C.Types
  • Read CSCharDefined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.C.Types
  • Read CSUSecondsDefined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.C.Types
  • Read CShortDefined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.C.Types
  • Read CSigAtomicDefined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.C.Types
  • Read CSizeDefined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.C.Types
  • Read CTimeDefined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.C.Types
  • Read CUCharDefined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.C.Types
  • Read CUIntDefined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.C.Types
  • Read CUIntMaxDefined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.C.Types
  • Read CUIntPtrDefined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.C.Types
  • Read CULLongDefined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.C.Types
  • Read CULongDefined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.C.Types
  • Read CUSecondsDefined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.C.Types
  • Read CUShortDefined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.C.Types
  • Read CWcharDefined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.C.Types
  • Read IntPtrDefined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.Ptr
  • Read WordPtrDefined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.Ptr
  • Read AssociativityDefined in ghc-internal-9.1003.0 · GHC.Internal.Generics
  • Read DecidedStrictnessDefined in ghc-internal-9.1003.0 · GHC.Internal.Generics
  • Read FixityDefined in ghc-internal-9.1003.0 · GHC.Internal.Generics
  • Read SourceStrictnessDefined in ghc-internal-9.1003.0 · GHC.Internal.Generics
  • Read SourceUnpackednessDefined in ghc-internal-9.1003.0 · GHC.Internal.Generics
  • Read SeekModeDefined in ghc-internal-9.1003.0 · GHC.Internal.IO.Device
  • Read ExitCodeDefined in ghc-internal-9.1003.0 · GHC.Internal.IO.Exception
  • Read BufferModeDefined in ghc-internal-9.1003.0 · GHC.Internal.IO.Handle.Types
  • Read NewlineDefined in ghc-internal-9.1003.0 · GHC.Internal.IO.Handle.Types
  • Read NewlineModeDefined in ghc-internal-9.1003.0 · GHC.Internal.IO.Handle.Types
  • Read IOModeDefined in ghc-internal-9.1003.0 · GHC.Internal.IO.IOMode
  • Read Int16Defined in ghc-internal-9.1003.0 · GHC.Internal.Int
  • Read Int32Defined in ghc-internal-9.1003.0 · GHC.Internal.Int
  • Read Int64Defined in ghc-internal-9.1003.0 · GHC.Internal.Int
  • Read Int8Defined in ghc-internal-9.1003.0 · GHC.Internal.Int
  • Read GCDetailsDefined in ghc-internal-9.1003.0 · GHC.Internal.Stats
  • Read RTSStatsDefined in ghc-internal-9.1003.0 · GHC.Internal.Stats
  • Read CBlkCntDefined in ghc-internal-9.1003.0 · GHC.Internal.System.Posix.Types
  • Read CBlkSizeDefined in ghc-internal-9.1003.0 · GHC.Internal.System.Posix.Types
  • Read CCcDefined in ghc-internal-9.1003.0 · GHC.Internal.System.Posix.Types
  • Read CClockIdDefined in ghc-internal-9.1003.0 · GHC.Internal.System.Posix.Types
  • Read CDevDefined in ghc-internal-9.1003.0 · GHC.Internal.System.Posix.Types
  • Read CFsBlkCntDefined in ghc-internal-9.1003.0 · GHC.Internal.System.Posix.Types
  • Read CFsFilCntDefined in ghc-internal-9.1003.0 · GHC.Internal.System.Posix.Types
  • Read CGidDefined in ghc-internal-9.1003.0 · GHC.Internal.System.Posix.Types
  • Read CIdDefined in ghc-internal-9.1003.0 · GHC.Internal.System.Posix.Types
  • Read CInoDefined in ghc-internal-9.1003.0 · GHC.Internal.System.Posix.Types
  • Read CKeyDefined in ghc-internal-9.1003.0 · GHC.Internal.System.Posix.Types
  • Read CModeDefined in ghc-internal-9.1003.0 · GHC.Internal.System.Posix.Types
  • Read CNfdsDefined in ghc-internal-9.1003.0 · GHC.Internal.System.Posix.Types
  • Read CNlinkDefined in ghc-internal-9.1003.0 · GHC.Internal.System.Posix.Types
  • Read COffDefined in ghc-internal-9.1003.0 · GHC.Internal.System.Posix.Types
  • Read CPidDefined in ghc-internal-9.1003.0 · GHC.Internal.System.Posix.Types
  • Read CRLimDefined in ghc-internal-9.1003.0 · GHC.Internal.System.Posix.Types
  • Read CSocklenDefined in ghc-internal-9.1003.0 · GHC.Internal.System.Posix.Types
  • Read CSpeedDefined in ghc-internal-9.1003.0 · GHC.Internal.System.Posix.Types
  • Read CSsizeDefined in ghc-internal-9.1003.0 · GHC.Internal.System.Posix.Types
  • Read CTcflagDefined in ghc-internal-9.1003.0 · GHC.Internal.System.Posix.Types
  • Read CUidDefined in ghc-internal-9.1003.0 · GHC.Internal.System.Posix.Types
  • Read FdDefined in ghc-internal-9.1003.0 · GHC.Internal.System.Posix.Types
  • Read LexemeDefined in ghc-internal-9.1003.0 · GHC.Internal.Read
  • Read SomeCharDefined in ghc-internal-9.1003.0 · GHC.Internal.TypeLits
  • Read SomeSymbolDefined in ghc-internal-9.1003.0 · GHC.Internal.TypeLits
  • Read SomeNatDefined in ghc-internal-9.1003.0 · GHC.Internal.TypeNats
  • Read GeneralCategoryDefined in ghc-internal-9.1003.0 · GHC.Internal.Read
  • Read Word16Defined in ghc-internal-9.1003.0 · GHC.Internal.Read
  • Read Word32Defined in ghc-internal-9.1003.0 · GHC.Internal.Read
  • Read Word64Defined in ghc-internal-9.1003.0 · GHC.Internal.Read
  • Read Word8Defined in ghc-internal-9.1003.0 · GHC.Internal.Read
  • Read BoolDefined in ghc-internal-9.1003.0 · GHC.Internal.Read
  • Read CharDefined in ghc-internal-9.1003.0 · GHC.Internal.Read
  • Read DoubleDefined in ghc-internal-9.1003.0 · GHC.Internal.Read
  • Read FloatDefined in ghc-internal-9.1003.0 · GHC.Internal.Read
  • Read IntDefined in ghc-internal-9.1003.0 · GHC.Internal.Read
  • Read OrderingDefined in ghc-internal-9.1003.0 · GHC.Internal.Read
  • Read WordDefined in ghc-internal-9.1003.0 · GHC.Internal.Read
  • Read OptionsDefined in invariant-0.6.4 · Data.Functor.Invariant.TH
  • Read ScientificDefined in scientific-0.3.8.0 · Data.Scientific

    Supports the skipping of parentheses and whitespaces. Example:

    > read " ( ((  -1.0e+3 ) ))" :: Scientific
    -1000.0

    (Note: This Read instance makes internal use of scientificP to parse the floating-point number.)

  • Read SMGenDefined in splitmix-0.1.3.1 · System.Random.SplitMix
    Example1 expression
    readMaybe "SMGen 1 1" :: Maybe SMGenJust (SMGen 1 1)
    Example1 expression
    readMaybe "SMGen 1 2" :: Maybe SMGenNothing
    Example1 expression
    readMaybe (show (mkSMGen 42)) :: Maybe SMGenJust (SMGen 9297814886316923340 13679457532755275413)
  • Read SMGenDefined in splitmix-0.1.3.1 · System.Random.SplitMix32
    Example1 expression
    readMaybe "SMGen 1 1" :: Maybe SMGenJust (SMGen 1 1)
    Example1 expression
    readMaybe "SMGen 1 2" :: Maybe SMGenNothing
    Example1 expression
    readMaybe (show (mkSMGen 42)) :: Maybe SMGenJust (SMGen 142593372 1604540297)
  • Read I8Defined in text-2.1.3 · Data.Text.Foreign
  • Read TextDefined in text-2.1.3 · Data.Text · orphan
  • Read TextDefined in text-2.1.3 · Data.Text.Lazy · orphan
  • Read FPFormatDefined in text-2.1.3 · Data.Text.Lazy.Builder.RealFloat
  • Read DatatypeVariantDefined in th-abstraction-0.7.1.0 · Language.Haskell.TH.Datatype
  • Read DayDefined in time-1.12.2 · Data.Time.Format.Parse · orphan
  • Read MonthDefined in time-1.12.2 · Data.Time.Calendar.Month

    Read as yyyy-mm.

  • Read QuarterDefined in time-1.12.2 · Data.Time.Calendar.Quarter

    Read as yyyy-Qn.

  • Read QuarterOfYearDefined in time-1.12.2 · Data.Time.Calendar.Quarter
  • Read DayOfWeekDefined in time-1.12.2 · Data.Time.Calendar.Week
  • Read DiffTimeDefined in time-1.12.2 · Data.Time.Clock.Internal.DiffTime
  • Read NominalDiffTimeDefined in time-1.12.2 · Data.Time.Clock.Internal.NominalDiffTime
  • Read UTCTimeDefined in time-1.12.2 · Data.Time.Format.Parse · orphan
  • Read UniversalTimeDefined in time-1.12.2 · Data.Time.Format.Parse · orphan
  • Read LocalTimeDefined in time-1.12.2 · Data.Time.Format.Parse · orphan
  • Read TimeOfDayDefined in time-1.12.2 · Data.Time.Format.Parse · orphan
  • Read TimeZoneDefined in time-1.12.2 · Data.Time.Format.Parse · orphan

    This only works for ±HHMM format, single-letter military time-zones, and these time-zones: "UTC", "UT", "GMT", "EST", "EDT", "CST", "CDT", "MST", "MDT", "PST", "PDT", per RFC 822 section 5.

  • Read ZonedTimeDefined in time-1.12.2 · Data.Time.Format.Parse · orphan

    This only works for a zonedTimeZone in ±HHMM format, single-letter military time-zones, and these time-zones: "UTC", "UT", "GMT", "EST", "EDT", "CST", "CDT", "MST", "MDT", "PST", "PDT", per RFC 822 section 5.

  • Read UUIDDefined in uuid-types-1.0.6 · Data.UUID.Types.Internal
  • Read UnpackedUUIDDefined in uuid-types-1.0.6 · Data.UUID.Types.Internal
  • Read ()Defined in ghc-internal-9.1003.0 · GHC.Internal.Read
  • Read a => Read (Complex a)Defined in base-4.20.2.0 · Data.Complex
  • Read a => Read (First a)Defined in base-4.20.2.0 · Data.Semigroup
  • Read a => Read (Last a)Defined in base-4.20.2.0 · Data.Semigroup
  • Read a => Read (Max a)Defined in base-4.20.2.0 · Data.Semigroup
  • Read a => Read (Min a)Defined in base-4.20.2.0 · Data.Semigroup
  • Read a => Read (Seq a)Defined in containers-0.7 · Data.Sequence.Internal
  • Read a => Read (ViewL a)Defined in containers-0.7 · Data.Sequence.Internal
  • Read a => Read (ViewR a)Defined in containers-0.7 · Data.Sequence.Internal
  • Read a => Read (Tree a)Defined in containers-0.7 · Data.Tree
  • Read a => Read (DNonEmpty a)Defined in dlist-1.0 · Data.DList.DNonEmpty.Internal
  • Read a => Read (DList a)Defined in dlist-1.0 · Data.DList.Internal
  • Read a => Read (NonEmpty a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Read
  • Read a => Read (And a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Bits
  • Read a => Read (Iff a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Bits
  • Read a => Read (Ior a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Bits
  • Read a => Read (Xor a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Bits
  • Read a => Read (Identity a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Functor.Identity

    This instance would be equivalent to the derived instances of the Identity newtype if the runIdentity field were removed

  • Read a => Read (First a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Monoid
  • Read a => Read (Last a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Monoid
  • Read a => Read (Down a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Ord

    This instance would be equivalent to the derived instances of the Down newtype if the getDown field were removed

  • Read a => Read (Dual a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Semigroup.Internal
  • Read a => Read (Product a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Semigroup.Internal
  • Read a => Read (Sum a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Semigroup.Internal
  • Read a => Read (ZipList a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Functor.ZipList
  • Read a => Read (Maybe a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Read
  • Read a => Read (Array a)Defined in primitive-0.9.1.0 · Data.Primitive.Array
  • Read a => Read (SmallArray a)Defined in primitive-0.9.1.0 · Data.Primitive.SmallArray
  • Read a => Read (Vector a)Defined in vector-0.13.2.0 · Data.Vector
  • Read a => Read (Vector a)Defined in vector-0.13.2.0 · Data.Vector.Strict
  • Read a => Read (a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Read
  • Read a => Read [a]Defined in ghc-internal-9.1003.0 · GHC.Internal.Read
  • Read e => Read (IntMap e)Defined in containers-0.7 · Data.IntMap.Internal
  • Read m => Read (WrappedMonoid m)Defined in base-4.20.2.0 · Data.Semigroup
  • Read p => Read (Par1 p)Defined in ghc-internal-9.1003.0 · GHC.Internal.Generics
  • Read vertex => Read (SCC vertex)Defined in containers-0.7 · Data.Graph
  • (Read a, Storable a) => Read (Vector a)Defined in vector-0.13.2.0 · Data.Vector.Storable
  • (Read a, Ord a) => Read (Set a)Defined in containers-0.7 · Data.Set.Internal
  • (Read a, Prim a) => Read (Vector a)Defined in vector-0.13.2.0 · Data.Vector.Primitive
  • (Read a, Unbox a) => Read (Vector a)Defined in vector-0.13.2.0 · Data.Vector.Unboxed · orphan
  • (Integral a, Read a) => Read (Ratio a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Read
  • (Hashable a, Read a) => Read (HashSet a)Defined in unordered-containers-0.2.21 · Data.HashSet.Internal
  • HasResolution a => Read (Fixed a)Defined in base-4.20.2.0 · Data.Fixed
  • Read (Proxy t)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Proxy
  • Read (U1 p)Defined in ghc-internal-9.1003.0 · GHC.Internal.Generics
  • Read (V1 p)Defined in ghc-internal-9.1003.0 · GHC.Internal.Generics
  • Read (f a) => Read (Coyoneda f a)Defined in kan-extensions-5.2.7 · Data.Functor.Coyoneda
  • (Read1 f, Read a) => Read (Cofree f a)Defined in free-5.2 · Control.Comonad.Cofree
  • (Read1 f, Read a) => Read (Free f a)Defined in free-5.2 · Control.Monad.Free
  • (Read1 f, Read a) => Read (Free f a)Defined in free-5.2 · Control.Monad.Free.Ap
  • (Read1 f, Read a) => Read (Lift f a)Defined in transformers-0.6.1.1 · Control.Applicative.Lift
  • (Read1 m, Read a) => Read (IterT m a)Defined in free-5.2 · Control.Monad.Trans.Iter
  • (Read1 m, Read a) => Read (MaybeT m a)Defined in transformers-0.6.1.1 · Control.Monad.Trans.Maybe
  • (Read1 w, Read a) => Read (CoiterT w a)Defined in free-5.2 · Control.Comonad.Trans.Coiter
  • (Functor f, Read (f a)) => Read (Yoneda f a)Defined in kan-extensions-5.2.7 · Data.Functor.Yoneda
  • (Ix a, Read a, Read b) => Read (Array a b)Defined in ghc-internal-9.1003.0 · GHC.Internal.Read
  • (Ix ix, Read ix, Read e, IArray UArray e) => Read (UArray ix e)Defined in array-0.5.8.0 · Data.Array.Base
  • (Read a, Read b) => Read (Arg a b)Defined in base-4.20.2.0 · Data.Semigroup
  • (Read a, Read b) => Read (Either a b)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Either
  • (Read a, Read b) => Read (a, b)Defined in ghc-internal-9.1003.0 · GHC.Internal.Read
  • (Ord k, Read k, Read e) => Read (Map k e)Defined in containers-0.7 · Data.Map.Internal
  • (Hashable k, Read k, Read e) => Read (HashMap k e)Defined in unordered-containers-0.2.21 · Data.HashMap.Internal
  • (GRead (Rep1 f a), Generic1 f) => Read (FunctorClassesDefault f a)Defined in transformers-compat-0.7.2 · Data.Functor.Classes.Generic.Internal
  • Read (bi a b) => Read (Biap bi a b)Defined in bifunctors-5.6.2 · Data.Bifunctor.Biap
  • Read (f a) => Read (Ap f a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Monoid
  • Read (f a) => Read (Alt f a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Semigroup.Internal
  • Read (f a) => Read (WrappedContravariant f a)Defined in invariant-0.6.4 · Data.Functor.Invariant
  • Read (f a) => Read (WrappedFunctor f a)Defined in invariant-0.6.4 · Data.Functor.Invariant
  • Read (f p) => Read (Rec1 f p)Defined in ghc-internal-9.1003.0 · GHC.Internal.Generics
  • Read (p (Fix p a) a) => Read (Fix p a)Defined in bifunctors-5.6.2 · Data.Bifunctor.Fix
  • Read (p a a) => Read (Join p a)Defined in bifunctors-5.6.2 · Data.Bifunctor.Join
  • Read (w (CofreeF f a (CofreeT f w a))) => Read (CofreeT f w a)Defined in free-5.2 · Control.Comonad.Trans.Cofree
  • Read a => Read (Const a b)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Functor.Const

    This instance would be equivalent to the derived instances of the Const newtype if the getConst field were removed

  • Read a => Read (Constant a b)Defined in transformers-0.6.1.1 · Data.Functor.Constant
  • Read b => Read (Tagged s b)Defined in tagged-0.8.9 · Data.Tagged
  • Coercible a b => Read (Coercion a b)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Type.Coercion
  • (Read1 f, Read1 m, Read a) => Read (FreeT f m a)Defined in free-5.2 · Control.Monad.Trans.Free
  • (Read1 f, Read1 m, Read a) => Read (FreeT f m a)Defined in free-5.2 · Control.Monad.Trans.Free.Ap
  • (Read1 f, Read a) => Read (Backwards f a)Defined in transformers-0.6.1.1 · Control.Applicative.Backwards
  • (Read1 f, Read a) => Read (IdentityT f a)Defined in transformers-0.6.1.1 · Control.Monad.Trans.Identity
  • (Read1 f, Read a) => Read (Reverse f a)Defined in transformers-0.6.1.1 · Data.Functor.Reverse
  • (Read1 f, Read e, Read a) => Read (ExceptT e f a)Defined in selective-0.7.0.1 · Control.Selective.Trans.Except
  • (Read a, Read (f b)) => Read (CofreeF f a b)Defined in free-5.2 · Control.Comonad.Trans.Cofree
  • (Read a, Read (f b)) => Read (FreeF f a b)Defined in free-5.2 · Control.Monad.Trans.Free
  • (Read a, Read (f b)) => Read (FreeF f a b)Defined in free-5.2 · Control.Monad.Trans.Free.Ap
  • (Read a, Read b, Read c) => Read (a, b, c)Defined in ghc-internal-9.1003.0 · GHC.Internal.Read
  • (Read e, Read1 m, Read a) => Read (ExceptT e m a)Defined in transformers-0.6.1.1 · Control.Monad.Trans.Except
  • (Read w, Read1 m, Read a) => Read (WriterT w m a)Defined in transformers-0.6.1.1 · Control.Monad.Trans.Writer.Lazy
  • (Read w, Read1 m, Read a) => Read (WriterT w m a)Defined in transformers-0.6.1.1 · Control.Monad.Trans.Writer.Strict
  • a ~ b => Read (a :~: b)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Type.Equality
  • Read c => Read (K1 i c p)Defined in ghc-internal-9.1003.0 · GHC.Internal.Generics
  • (Read (f a), Read (g a)) => Read (Product f g a)Defined in base-4.20.2.0 · Data.Functor.Product
  • (Read (f a), Read (g a)) => Read (Sum f g a)Defined in base-4.20.2.0 · Data.Functor.Sum
  • (Read (f p), Read (g p)) => Read ((:*:) f g p)Defined in ghc-internal-9.1003.0 · GHC.Internal.Generics
  • (Read (f p), Read (g p)) => Read ((:+:) f g p)Defined in ghc-internal-9.1003.0 · GHC.Internal.Generics
  • (Read a, Read b, Read c, Read d) => Read (a, b, c, d)Defined in ghc-internal-9.1003.0 · GHC.Internal.Read
  • a ~~ b => Read (a :~~: b)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Type.Equality
  • Read (f (g a)) => Read (Compose f g a)Defined in base-4.20.2.0 · Data.Functor.Compose
  • Read (f (g p)) => Read ((:.:) f g p)Defined in ghc-internal-9.1003.0 · GHC.Internal.Generics
  • Read (f a) => Read (Clown f a b)Defined in bifunctors-5.6.2 · Data.Bifunctor.Clown
  • Read (f p) => Read (M1 i c f p)Defined in ghc-internal-9.1003.0 · GHC.Internal.Generics
  • Read (g b) => Read (Joker g a b)Defined in bifunctors-5.6.2 · Data.Bifunctor.Joker
  • Read (p a b) => Read (WrappedBifunctor p a b)Defined in bifunctors-5.6.2 · Data.Bifunctor.Wrapped
  • Read (p a b) => Read (WrappedProfunctor p a b)Defined in invariant-0.6.4 · Data.Functor.Invariant
  • Read (p b a) => Read (Flip p a b)Defined in bifunctors-5.6.2 · Data.Bifunctor.Flip
  • (Read a, Read b, Read c, Read d, Read e) => Read (a, b, c, d, e)Defined in ghc-internal-9.1003.0 · GHC.Internal.Read
  • (Read (f a b), Read (g a b)) => Read (Product f g a b)Defined in bifunctors-5.6.2 · Data.Bifunctor.Product
  • (Read (p a b), Read (q a b)) => Read (Sum p q a b)Defined in bifunctors-5.6.2 · Data.Bifunctor.Sum
  • (Read a, Read b, Read c, Read d, Read e, Read f) => Read (a, b, c, d, e, f)Defined in ghc-internal-9.1003.0 · GHC.Internal.Read
  • Read (f (p a b)) => Read (Tannen f p a b)Defined in bifunctors-5.6.2 · Data.Bifunctor.Tannen
  • (Read a, Read b, Read c, Read d, Read e, Read f, Read g) => Read (a, b, c, d, e, f, g)Defined in ghc-internal-9.1003.0 · GHC.Internal.Read
  • (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)Defined in ghc-internal-9.1003.0 · GHC.Internal.Read
  • Read (p (f a) (g b)) => Read (Biff p f g a b)Defined in bifunctors-5.6.2 · Data.Bifunctor.Biff
  • (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)Defined in ghc-internal-9.1003.0 · GHC.Internal.Read
  • (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)Defined in ghc-internal-9.1003.0 · GHC.Internal.Read
  • (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)Defined in ghc-internal-9.1003.0 · GHC.Internal.Read
  • (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)Defined in ghc-internal-9.1003.0 · GHC.Internal.Read
  • (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)Defined in ghc-internal-9.1003.0 · GHC.Internal.Read
  • (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)Defined in ghc-internal-9.1003.0 · GHC.Internal.Read
  • (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)Defined in ghc-internal-9.1003.0 · GHC.Internal.Read
newtypenewtype ReadPrec a
#
Instances7Monad, Functor, MonadFail, Applicative, Alternative, MonadPlus, …
  • Monad ReadPrecDefined in ghc-internal-9.1003.0 · GHC.Internal.Text.ParserCombinators.ReadPrec
  • Functor ReadPrecDefined in ghc-internal-9.1003.0 · GHC.Internal.Text.ParserCombinators.ReadPrec
  • MonadFail ReadPrecDefined in ghc-internal-9.1003.0 · GHC.Internal.Text.ParserCombinators.ReadPrec
  • Applicative ReadPrecDefined in ghc-internal-9.1003.0 · GHC.Internal.Text.ParserCombinators.ReadPrec
  • Alternative ReadPrecDefined in ghc-internal-9.1003.0 · GHC.Internal.Text.ParserCombinators.ReadPrec
  • MonadPlus ReadPrecDefined in ghc-internal-9.1003.0 · GHC.Internal.Text.ParserCombinators.ReadPrec
  • Invariant ReadPrecDefined in invariant-0.6.4 · Data.Functor.Invariant
valuelex :: ReadS String
#

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

valueread :: Read a => String -> a
#

The read function reads input from a string, which must be completely consumed by the input process. read fails with an error if the parse is unsuccessful, and it is therefore discouraged from being used in real applications. Use readMaybe or readEither for safe alternatives.

Example1 expression
read "123" :: Int123
Example1 expression
read "hello" :: Int*** Exception: Prelude.read: no parse
valuereadEither :: Read a => String -> Either String a
#

Parse a string using the Read instance. Succeeds if there is exactly one valid result. A Left value indicates a parse error.

Example1 expression
readEither "123" :: Either String IntRight 123
Example1 expression
readEither "hello" :: Either String IntLeft "Prelude.read: no parse"
valuereadMaybe :: Read a => String -> Maybe a
#

Parse a string using the Read instance. Succeeds if there is exactly one valid result.

Example1 expression
readMaybe "123" :: Maybe IntJust 123
Example1 expression
readMaybe "hello" :: Maybe IntNothing
typetype ReadS a = String -> [(a, String)]
#

A parser for a type a, represented as a function that takes a String and returns a list of possible parses as (a,String) pairs.

Note that this kind of backtracking parser is very inefficient; reading a large structure may be quite slow (cf ReadP).

valueget :: ReadPrec Char
#

Consumes and returns the next character. Fails if there is no input left.

valueparens :: 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

valueprec :: Prec -> ReadPrec a -> ReadPrec a
#

(prec n p) checks whether the precedence context is less than or equal to n, and

  • if not, fails

  • if so, parses p in context n.

valuelook :: ReadPrec String
#

Look-ahead: returns the part of the input that is left, without consuming it.

value(<++) :: ReadPrec a -> ReadPrec a -> ReadPrec a
#

Local, exclusive, left-biased choice: If left parser locally produces any result at all, then right parser is not used.