HORIZON HASKELLDocslts/ghc-9.10.x248f8f02026-10-05Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · 248f8f0 · 2026-10-05

Moduleextra-1.8Haskell2010

Text.Read.Extra

Deprecated. Use Text.Read directly

This module provides Text.Read with functions added in later versions.

Currently this module has no functionality beyond Text.Read.

  • 4 types
  • 1 class
  • 25 values
  • Packageextra-1.8
  • Exports30
  • LanguageHaskell2010
  • LicenceBSD-3-Clause
  • SourceExtra.hs
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.

Instances194Read, …
  • 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 ClockDefined in clock-0.8.4 · System.Clock
  • Read TimeSpecDefined in clock-0.8.4 · System.Clock
  • Read SecondsDefined in clock-0.8.4 · System.Clock.Seconds
  • Read FileTypeDefined in directory-1.3.8.5 · System.Directory.Internal.Common
  • Read PermissionsDefined in directory-1.3.8.5 · System.Directory.Internal.Common
  • Read XdgDirectoryDefined in directory-1.3.8.5 · System.Directory.Internal.Common
  • Read XdgDirectoryListDefined in directory-1.3.8.5 · System.Directory.Internal.Common
  • 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 CommunicationHandleDefined in process-1.6.26.1 · System.Process.CommunicationHandle.Internal
  • 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 RTLDFlagsDefined in unix-2.8.7.0 · System.Posix.DynamicLinker.Prim
  • Read CAttributesDefined in unix-2.8.7.0 · System.Posix.Files.Common
  • Read StatxFlagsDefined in unix-2.8.7.0 · System.Posix.Files.Common
  • Read StatxMaskDefined in unix-2.8.7.0 · System.Posix.Files.Common
  • Read OpenFileFlagsDefined in unix-2.8.7.0 · System.Posix.IO.Common
  • Read OpenModeDefined in unix-2.8.7.0 · System.Posix.IO.Common
  • Read GroupEntryDefined in unix-2.8.7.0 · System.Posix.User.Common
  • Read UserEntryDefined in unix-2.8.7.0 · System.Posix.User.Common
  • 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 (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 (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 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
  • (Integral a, Read a) => Read (Ratio a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Read
  • 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
  • (Read1 f, Read a) => Read (Lift f a)Defined in transformers-0.6.1.1 · Control.Applicative.Lift
  • (Read1 m, Read a) => Read (MaybeT m a)Defined in transformers-0.6.1.1 · Control.Monad.Trans.Maybe
  • (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
  • 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 p) => Read (Rec1 f p)Defined in ghc-internal-9.1003.0 · GHC.Internal.Generics
  • 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
  • Coercible a b => Read (Coercion a b)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Type.Coercion
  • (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
  • (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 p) => Read (M1 i c f p)Defined in ghc-internal-9.1003.0 · GHC.Internal.Generics
  • (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 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 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 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
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
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).

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

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.

valueget :: ReadPrec Char
#

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

valuelook :: ReadPrec String
#

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

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.

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
newtypenewtype ReadPrec a
#
Instances6Monad, 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