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

Modulerelude-1.2.0.0Haskell2010

Relude.String.Reexport

SPDX-License-Identifier : MIT Maintainer : Kowainik xrom.xkov@gmail.com Stability : Stable Portability : Portable

Reexports functions to work with Text, ByteString and ShortByteString types.

  • 7 types
  • 2 classes
  • 12 values
  • Packagerelude-1.2.0.0
  • Exports21
  • LanguageHaskell2010
  • LicenceMIT
  • SourceReexport.hs

String

5 declarations
typetype String = [Char]
#

String is an alias for a list of characters.

String constants in Haskell are values of type String. That means if you write a string literal like "hello world", it will have the type [Char], which is the same as String.

Note: You can ask the compiler to automatically infer different types with the -XOverloadedStrings language extension, for example "hello world" :: Text. See IsString for more information.

Because String is just a list of characters, you can use normal list functions to do basic string manipulation. See Data.List for operations on lists.

Performance considerations

[Char] is a relatively memory-inefficient type. It is a linked list of boxed word-size characters, internally it looks something like:

╭─────┬───┬──╮  ╭─────┬───┬──╮  ╭─────┬───┬──╮  ╭────╮
│ (:) │   │ ─┼─>│ (:) │   │ ─┼─>│ (:) │   │ ─┼─>│ [] │
╰─────┴─┼─┴──╯  ╰─────┴─┼─┴──╯  ╰─────┴─┼─┴──╯  ╰────╯
        v               v               v
       'a'             'b'             'c'

The String "abc" will use 5*3+1 = 16 (in general 5n+1) words of space in memory.

Furthermore, operations like (++) (string concatenation) are O(n) (in the left argument).

For historical reasons, the base library uses String in a lot of places for the conceptual simplicity, but library code dealing with user-data should use the text package for Unicode text, or the the bytestring package for binary data.

Instances6ToLText, ToString, ToText, ConvertUtf8
classclass IsString a where
#

IsString is used in combination with the -XOverloadedStrings language extension to convert the literals to different string types.

For example, if you use the text package, you can say

{-# LANGUAGE OverloadedStrings  #-}

myText = "hello world" :: Text

Internally, the extension will convert this to the equivalent of

myText = fromString @Text ("hello world" :: String)

Note: You can use fromString in normal code as well, but the usual performance/memory efficiency problems with String apply.

Methods

Instances14IsString, …
  • IsString BuilderDefined in bytestring-0.12.2.0 · Data.ByteString.Builder · orphan
  • IsString ByteStringDefined in bytestring-0.12.2.0 · Data.ByteString.Internal.Type

    Beware: fromString truncates multi-byte characters to octets. e.g. "枯朶に烏のとまりけり秋の暮" becomes �6k�nh~�Q��n�

  • IsString ByteStringDefined in bytestring-0.12.2.0 · Data.ByteString.Lazy.Internal

    Beware: fromString truncates multi-byte characters to octets. e.g. "枯朶に烏のとまりけり秋の暮" becomes �6k�nh~�Q��n�

  • IsString ShortByteStringDefined in bytestring-0.12.2.0 · Data.ByteString.Short.Internal

    Beware: fromString truncates multi-byte characters to octets. e.g. "枯朶に烏のとまりけり秋の暮" becomes �6k�nh~�Q��n�

  • IsString DocDefined in pretty-1.1.3.6 · Text.PrettyPrint.HughesPJ
  • IsString TextDefined in text-2.1.3 · Data.Text · orphan

    Performs replacement on invalid scalar values:

    Example2 expressions
    :set -XOverloadedStrings"\55555" :: Text"\65533"
  • IsString BuilderDefined in text-2.1.3 · Data.Text.Internal.Builder

    Performs replacement on invalid scalar values:

    Example2 expressions
    :set -XOverloadedStrings"\55555" :: Builder"\65533"
  • IsString TextDefined in text-2.1.3 · Data.Text.Lazy · orphan

    Performs replacement on invalid scalar values:

    Example2 expressions
    :set -XOverloadedStrings"\55555" :: Data.Text.Lazy.Text"\65533"
  • IsString (Doc a)Defined in pretty-1.1.3.6 · Text.PrettyPrint.Annotated.HughesPJ
  • IsString a => IsString (Identity a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.String
  • (IsString a, Hashable a) => IsString (Hashed a)Defined in hashable-1.4.7.0 · Data.Hashable.Class
  • a ~ Char => IsString (Seq a)Defined in containers-0.7 · Data.Sequence.Internal
  • a ~ Char => IsString [a]Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.String

    (a ~ Char) context was introduced in 4.9.0.0

  • IsString a => IsString (Const a b)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.String
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
Instances181Read, …
  • 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 UndefinedDefined in relude-1.2.0.0 · Relude.Debug
  • 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 ()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 (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 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, Ord a) => Read (Set a)Defined in containers-0.7 · Data.Set.Internal
  • (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
  • (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
  • (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
  • 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
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

Text

12 declarations
datadata Text
#

A space efficient, packed, unboxed Unicode text type.

Instances24IsList, Eq, Data, Ord, Read, Show, …
  • IsList TextDefined in text-2.1.3 · Data.Text · orphan

    Performs replacement on invalid scalar values:

    Example2 expressions
    :set -XOverloadedLists['\55555'] :: Text"\65533"
  • Eq TextDefined in text-2.1.3 · Data.Text · orphan
  • Data TextDefined in text-2.1.3 · Data.Text · orphan

    This instance preserves data abstraction at the cost of inefficiency. We omit reflection services for the sake of data abstraction.

    This instance was created by copying the updated behavior of Data.Set.Set and Data.Map.Data.Map.Map. If you feel a mistake has been made, please feel free to submit improvements.

    The original discussion is archived here: could we get a Data instance for Data.Text.Text?

    The followup discussion that changed the behavior of Set and Data.Map.Map is archived here: Proposal: Allow gunfold for Data.Map, ...

  • Ord TextDefined in text-2.1.3 · Data.Text · orphan
  • Read TextDefined in text-2.1.3 · Data.Text · orphan
  • Show TextDefined in text-2.1.3 · Data.Text.Show · orphan
  • IsString TextDefined in text-2.1.3 · Data.Text · orphan

    Performs replacement on invalid scalar values:

    Example2 expressions
    :set -XOverloadedStrings"\55555" :: Text"\65533"
  • Semigroup TextDefined in text-2.1.3 · Data.Text · orphan

    Beware: stimes will crash if the given number does not fit into an Int.

  • Monoid TextDefined in text-2.1.3 · Data.Text · orphan
  • PrintfArg TextDefined in text-2.1.3 · Data.Text · orphan
  • NFData TextDefined in text-2.1.3 · Data.Text · orphan
  • Binary TextDefined in text-2.1.3 · Data.Text · orphan
  • Hashable TextDefined in hashable-1.4.7.0 · Data.Hashable.Class
  • One TextDefined in relude-1.2.0.0 · Relude.Container.One

    Create singleton strict Text.

    Example1 expression
    one 'a' :: Text"a"
    law> length (one x) ≡ 1
    
  • ToLText TextDefined in relude-1.2.0.0 · Relude.String.Conversion
  • ToString TextDefined in relude-1.2.0.0 · Relude.String.Conversion
  • ToText TextDefined in relude-1.2.0.0 · Relude.String.Conversion
  • Lift TextDefined in text-2.1.3 · Data.Text · orphan
  • ConvertUtf8 Text ByteStringDefined in relude-1.2.0.0 · Relude.String.Conversion
  • ConvertUtf8 Text ShortByteStringDefined in relude-1.2.0.0 · Relude.String.Conversion
  • ConvertUtf8 Text LByteStringDefined in relude-1.2.0.0 · Relude.String.Conversion
  • LazyStrict LText TextDefined in relude-1.2.0.0 · Relude.String.Conversion
  • type Item Text = CharDefined in text-2.1.3 · Data.Text · orphan
  • type OneItem Text = CharDefined in relude-1.2.0.0 · Relude.Container.One
valuelines :: IsText t "lines" => t -> [t]
#

lines takes Text and splits it into the list by lines.

Actual type of this function is the following:

lines :: Text -> [Text]

but it was given a more complex type to provide friendlier compile time errors.

Example5 expressions
lines ""[]lines "one line"["one line"]lines "line 1\nline 2"["line 1","line 2"]lines ("string line" :: String)...... 'lines' works with 'Text', not 'String'.      Possible fixes:          1. Make sure OverloadedStrings extension is enabled.          2. Apply 'toText' to a single value.          3. Apply 'map toText' to the list value....lines True...... 'lines' works with 'Text'      But given: 'Bool'...
valueunlines :: IsText t "unlines" => [t] -> t
#

unlines takes list of Text values and joins them with line separator.

Actual type of this function is the following:

unlines :: [Text] -> Text

but it was given a more complex type to provide friendlier compile time errors.

Example5 expressions
unlines []""unlines ["line 1"]"line 1\n"unlines ["first line", "second line"]"first line\nsecond line\n"unlines (["line 1", "line 2"] :: [String])...... 'unlines' works with 'Text', not 'String'.      Possible fixes:          1. Make sure OverloadedStrings extension is enabled.          2. Apply 'toText' to a single value.          3. Apply 'map toText' to the list value....unlines [True, False]...... 'unlines' works with 'Text'      But given: 'Bool'...
valuewords :: IsText t "words" => t -> [t]
#

words takes Text and splits it into the list by words.

Actual type of this function is the following:

words :: Text -> [Text]

but it was given a more complex type to provide friendlier compile time errors.

Example5 expressions
words ""[]words "one line"["one","line"]words "   >_<   "[">_<"]words ("string words" :: String)...... 'words' works with 'Text', not 'String'.      Possible fixes:          1. Make sure OverloadedStrings extension is enabled.          2. Apply 'toText' to a single value.          3. Apply 'map toText' to the list value....words True...... 'words' works with 'Text'      But given: 'Bool'...
valueunwords :: IsText t "unwords" => [t] -> t
#

unwords takes list of Text values and joins them with space character.

Actual type of this function is the following:

unwords :: [Text] -> Text

but it was given a more complex type to provide friendlier compile time errors.

Example5 expressions
unwords []""unwords ["singleWord"]"singleWord"unwords ["word", "another"]"word another"unwords (["word", "another"] :: [String])...... 'unwords' works with 'Text', not 'String'.      Possible fixes:          1. Make sure OverloadedStrings extension is enabled.          2. Apply 'toText' to a single value.          3. Apply 'map toText' to the list value....unwords [True, False]...... 'unwords' works with 'Text'      But given: 'Bool'...
typetype OnError a b = String -> Maybe a -> Maybe b
#

Function type for handling a coding error. It is supplied with two inputs:

  • A String that describes the error.

  • The input value that caused the error. If the error arose because the end of input was reached or could not be identified precisely, this value will be Nothing.

If the handler returns a value wrapped with Just, that value will be used in the output as the replacement for the invalid input. If it returns Nothing, no value will be used in the output.

Should the handler need to abort processing, it should use error or throw an exception (preferably a UnicodeException). It may use the description provided to construct a more helpful error report.

ByteString

1 declaration
datadata ByteString
#

A space-efficient representation of a Word8 vector, supporting many efficient operations.

A ByteString contains 8-bit bytes, or by using the operations from Data.ByteString.Char8 it can be interpreted as containing 8-bit characters.

Instances23IsList, Eq, Data, Ord, Read, Show, …
  • IsList ByteStringDefined in bytestring-0.12.2.0 · Data.ByteString.Internal.Type
  • Eq ByteStringDefined in bytestring-0.12.2.0 · Data.ByteString.Internal.Type
  • Data ByteStringDefined in bytestring-0.12.2.0 · Data.ByteString.Internal.Type
  • Ord ByteStringDefined in bytestring-0.12.2.0 · Data.ByteString.Internal.Type
  • Read ByteStringDefined in bytestring-0.12.2.0 · Data.ByteString.Internal.Type
  • Show ByteStringDefined in bytestring-0.12.2.0 · Data.ByteString.Internal.Type
  • IsString ByteStringDefined in bytestring-0.12.2.0 · Data.ByteString.Internal.Type

    Beware: fromString truncates multi-byte characters to octets. e.g. "枯朶に烏のとまりけり秋の暮" becomes �6k�nh~�Q��n�

  • Semigroup ByteStringDefined in bytestring-0.12.2.0 · Data.ByteString.Internal.Type
  • Monoid ByteStringDefined in bytestring-0.12.2.0 · Data.ByteString.Internal.Type
  • NFData ByteStringDefined in bytestring-0.12.2.0 · Data.ByteString.Internal.Type
  • Binary ByteStringDefined in binary-0.8.9.3 · Data.Binary.Class
  • Hashable ByteStringDefined in hashable-1.4.7.0 · Data.Hashable.Class
  • One ByteStringDefined in relude-1.2.0.0 · Relude.Container.One

    Create singleton strict ByteString.

    Example1 expression
    one 97 :: ByteString"a"
    law> length (one x) ≡ 1
    
  • EncodingError ToLText "ByteString" "LText" => ToLText ByteStringDefined in relude-1.2.0.0 · Relude.String.Conversion

    ⚠️CAUTION⚠️ This instance is for custom error display only.

    You should always specify encoding of bytes explicitly.

    In case it is used by mistake, the user will see the following:

    Example1 expression
    toLText ("some string" :: ByteString)...... Type 'ByteString' doesn't have instance of 'ToLText'.      Use 'decodeUtf8' or 'decodeUtf8Strict' to convert from UTF-8:          decodeUtf8       :: ByteString -> LText          decodeUtf8Strict :: ByteString -> Either UnicodeException LText...
  • EncodingError ToString "ByteString" "String" => ToString ByteStringDefined in relude-1.2.0.0 · Relude.String.Conversion

    ⚠️CAUTION⚠️ This instance is for custom error display only.

    You should always specify encoding of bytes explicitly.

    In case it is used by mistake, the user will see the following:

    Example1 expression
    toString ("some string" :: ByteString)...... Type 'ByteString' doesn't have instance of 'ToString'.      Use 'decodeUtf8' or 'decodeUtf8Strict' to convert from UTF-8:          decodeUtf8       :: ByteString -> String          decodeUtf8Strict :: ByteString -> Either UnicodeException String...
  • EncodingError ToText "ByteString" "Text" => ToText ByteStringDefined in relude-1.2.0.0 · Relude.String.Conversion

    ⚠️CAUTION⚠️ This instance is for custom error display only.

    You should always specify encoding of bytes explicitly.

    In case it is used by mistake, the user will see the following:

    Example1 expression
    toText ("some string" :: ByteString)...... Type 'ByteString' doesn't have instance of 'ToText'.      Use 'decodeUtf8' or 'decodeUtf8Strict' to convert from UTF-8:          decodeUtf8       :: ByteString -> Text          decodeUtf8Strict :: ByteString -> Either UnicodeException Text...
  • Lift ByteStringDefined in bytestring-0.12.2.0 · Data.ByteString.Internal.Type
  • ConvertUtf8 String ByteStringDefined in relude-1.2.0.0 · Relude.String.Conversion
  • ConvertUtf8 LText ByteStringDefined in relude-1.2.0.0 · Relude.String.Conversion
  • ConvertUtf8 Text ByteStringDefined in relude-1.2.0.0 · Relude.String.Conversion
  • LazyStrict LByteString ByteStringDefined in relude-1.2.0.0 · Relude.String.Conversion
  • type Item ByteString = Word8Defined in bytestring-0.12.2.0 · Data.ByteString.Internal.Type
  • type OneItem ByteString = Word8Defined in relude-1.2.0.0 · Relude.Container.One

ShortByteString

3 declarations
newtypenewtype ShortByteString
#

A compact representation of a Word8 vector.

It has a lower memory overhead than a ByteString and does not contribute to heap fragmentation. It can be converted to or from a ByteString (at the cost of copying the string data). It supports very few other operations.

Instances24IsList, Eq, Data, Ord, Read, Show, …
  • IsList ShortByteStringDefined in bytestring-0.12.2.0 · Data.ByteString.Short.Internal
  • Eq ShortByteStringDefined in bytestring-0.12.2.0 · Data.ByteString.Short.Internal
  • Data ShortByteStringDefined in bytestring-0.12.2.0 · Data.ByteString.Short.Internal
  • Ord ShortByteStringDefined in bytestring-0.12.2.0 · Data.ByteString.Short.Internal

    Lexicographic order.

  • Read ShortByteStringDefined in bytestring-0.12.2.0 · Data.ByteString.Short.Internal
  • Show ShortByteStringDefined in bytestring-0.12.2.0 · Data.ByteString.Short.Internal
  • IsString ShortByteStringDefined in bytestring-0.12.2.0 · Data.ByteString.Short.Internal

    Beware: fromString truncates multi-byte characters to octets. e.g. "枯朶に烏のとまりけり秋の暮" becomes �6k�nh~�Q��n�

  • Generic ShortByteStringDefined in bytestring-0.12.2.0 · Data.ByteString.Short.Internal
  • Semigroup ShortByteStringDefined in bytestring-0.12.2.0 · Data.ByteString.Short.Internal
  • Monoid ShortByteStringDefined in bytestring-0.12.2.0 · Data.ByteString.Short.Internal
  • NFData ShortByteStringDefined in bytestring-0.12.2.0 · Data.ByteString.Short.Internal
  • Binary ShortByteStringDefined in binary-0.8.9.3 · Data.Binary.Class
  • Hashable ShortByteStringDefined in hashable-1.4.7.0 · Data.Hashable.Class
  • One ShortByteStringDefined in relude-1.2.0.0 · Relude.Container.One

    Create singleton ShortByteString.

    Example1 expression
    one 97 :: ShortByteString"a"
    law> length (one x) ≡ 1
    
  • EncodingError ToLText "ShortByteString" "LText" => ToLText ShortByteStringDefined in relude-1.2.0.0 · Relude.String.Conversion

    ⚠️CAUTION⚠️ This instance is for custom error display only.

    You should always specify encoding of bytes explicitly.

    In case it is used by mistake, the user will see the following:

    Example1 expression
    toLText ("some string" :: ShortByteString)...... Type 'ShortByteString' doesn't have instance of 'ToLText'.      Use 'decodeUtf8' or 'decodeUtf8Strict' to convert from UTF-8:          decodeUtf8       :: ShortByteString -> LText          decodeUtf8Strict :: ShortByteString -> Either UnicodeException LText...
  • EncodingError ToString "ShortByteString" "String" => ToString ShortByteStringDefined in relude-1.2.0.0 · Relude.String.Conversion

    ⚠️CAUTION⚠️ This instance is for custom error display only.

    You should always specify encoding of bytes explicitly.

    In case it is used by mistake, the user will see the following:

    Example1 expression
    toString ("some string" :: ShortByteString)...... Type 'ShortByteString' doesn't have instance of 'ToString'.      Use 'decodeUtf8' or 'decodeUtf8Strict' to convert from UTF-8:          decodeUtf8       :: ShortByteString -> String          decodeUtf8Strict :: ShortByteString -> Either UnicodeException String...
  • EncodingError ToText "ShortByteString" "Text" => ToText ShortByteStringDefined in relude-1.2.0.0 · Relude.String.Conversion

    ⚠️CAUTION⚠️ This instance is for custom error display only.

    You should always specify encoding of bytes explicitly.

    In case it is used by mistake, the user will see the following:

    Example1 expression
    toText ("some string" :: ShortByteString)...... Type 'ShortByteString' doesn't have instance of 'ToText'.      Use 'decodeUtf8' or 'decodeUtf8Strict' to convert from UTF-8:          decodeUtf8       :: ShortByteString -> Text          decodeUtf8Strict :: ShortByteString -> Either UnicodeException Text...
  • Lift ShortByteStringDefined in bytestring-0.12.2.0 · Data.ByteString.Short.Internal
  • ConvertUtf8 String ShortByteStringDefined in relude-1.2.0.0 · Relude.String.Conversion
  • ConvertUtf8 LText ShortByteStringDefined in relude-1.2.0.0 · Relude.String.Conversion
  • ConvertUtf8 Text ShortByteStringDefined in relude-1.2.0.0 · Relude.String.Conversion
  • type Rep ShortByteString = D1 ('MetaData "ShortByteString" "Data.ByteString.Short.Internal" "bytestring-0.12.2.0-e345" 'True) (C1 ('MetaCons "ShortByteString" 'PrefixI 'True) (S1 ('MetaSel ('Just "unShortByteString") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 ByteArray)))Defined in bytestring-0.12.2.0 · Data.ByteString.Short.Internal
  • type Item ShortByteString = Word8Defined in bytestring-0.12.2.0 · Data.ByteString.Short.Internal
  • type OneItem ShortByteString = Word8Defined in relude-1.2.0.0 · Relude.Container.One