relude-1.2.2.0: Safe, performant, user-friendly and lightweight Haskell Standard Library

Copyright | (c) 2016 Stephen Diehl (c) 2016-2018 Serokell (c) 2018-2023 Kowainik
License | MIT
Maintainer | Kowainik <xrom.xkov@gmail.com>
Stability | Stable
Portability | Portable
Safe Haskell | Safe
Language | Haskell2010

Relude.String.Reexport

Contents

- String
- Text
- ByteString
- ShortByteString

Description

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

Synopsis

- class IsString a where
  - fromString :: String -> a
- type String = [Char]
- class Read a
- reads :: Read a => ReadS a
- readMaybe :: Read a => String -> Maybe a
- data Text
- lines :: IsText t "lines" => t -> [t]
- unlines :: IsText t "unlines" => [t] -> t
- words :: IsText t "words" => t -> [t]
- unwords :: IsText t "unwords" => [t] -> t
- decodeUtf8With :: OnDecodeError -> ByteString -> Text
- decodeUtf8' :: ByteString -> Either UnicodeException Text
- data UnicodeException
- type OnDecodeError = OnError Word8 Char
- type OnError a b = String -> Maybe a -> Maybe b
- strictDecode :: OnDecodeError
- lenientDecode :: OnDecodeError
- data ByteString
- data ShortByteString
- toShort :: ByteString -> ShortByteString
- fromShort :: ShortByteString -> ByteString

# String

class 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

fromString :: String -> a #

#### Instances

Instances details

IsString ByteString | Beware: `fromString` truncates multi-byte characters to octets. e.g. "枯朶に烏のとまりけり秋の暮" becomes �6k�nh~�Q��n�
Instance details Defined in Data.ByteString.Internal.Type Methods fromString :: String -> ByteString #
IsString ByteString | Beware: `fromString` truncates multi-byte characters to octets. e.g. "枯朶に烏のとまりけり秋の暮" becomes �6k�nh~�Q��n�
Instance details Defined in Data.ByteString.Lazy.Internal Methods fromString :: String -> ByteString #
IsString ShortByteString | Beware: `fromString` truncates multi-byte characters to octets. e.g. "枯朶に烏のとまりけり秋の暮" becomes �6k�nh~�Q��n�
Instance details Defined in Data.ByteString.Short.Internal Methods fromString :: String -> ShortByteString #
IsString Doc |
Instance details Defined in Text.PrettyPrint.HughesPJ Methods fromString :: String -> Doc #
IsString Builder | Performs replacement on invalid scalar values:
    >>> :set -XOverloadedStrings
    >>> "\55555" :: Builder
    "\65533"
Instance details Defined in Data.Text.Internal.Builder Methods fromString :: String -> Builder #
a ~ Char => IsString (Seq a) | Since: containers-0.5.7
Instance details Defined in Data.Sequence.Internal Methods fromString :: String -> Seq a #
IsString a => IsString (Identity a) | @since base-4.9.0.0
Instance details Defined in GHC.Internal.Data.String Methods fromString :: String -> Identity a #
(IsString a, Hashable a) => IsString (Hashed a) |
Instance details Defined in Data.Hashable.Class Methods fromString :: String -> Hashed a #
IsString (Doc a) |
Instance details Defined in Text.PrettyPrint.Annotated.HughesPJ Methods fromString :: String -> Doc a #
a ~ Char => IsString [a] | `(a ~ Char)` context was introduced in `4.9.0.0` @since base-2.01
Instance details Defined in GHC.Internal.Data.String Methods fromString :: String -> [a] #
IsString a => IsString (Const a b) | @since base-4.9.0.0
Instance details Defined in GHC.Internal.Data.String Methods fromString :: String -> Const a b #

type 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

Expand

`[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.

class Read a #

Parsing of `String`s, producing values.

Derived instances of `Read` make the following assumptions, which derived instances of `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

Minimal complete definition

readsPrec | readPrec

#### Instances

Instances details

Read ByteString |
Instance details Defined in Data.ByteString.Internal.Type Methods readsPrec :: Int -> ReadS ByteString # readList :: ReadS [ByteString] # readPrec :: ReadPrec ByteString # readListPrec :: ReadPrec [ByteString] #
Read ByteString |
Instance details Defined in Data.ByteString.Lazy.Internal Methods readsPrec :: Int -> ReadS ByteString # readList :: ReadS [ByteString] # readPrec :: ReadPrec ByteString # readListPrec :: ReadPrec [ByteString] #
Read ShortByteString |
Instance details Defined in Data.ByteString.Short.Internal Methods readsPrec :: Int -> ReadS ShortByteString # readList :: ReadS [ShortByteString] # readPrec :: ReadPrec ShortByteString # readListPrec :: ReadPrec [ShortByteString] #
Read IntSet |
Instance details Defined in Data.IntSet.Internal Methods readsPrec :: Int -> ReadS IntSet # readList :: ReadS [IntSet] # readPrec :: ReadPrec IntSet # readListPrec :: ReadPrec [IntSet] #
Read Void | Reading a `Void` value is always a parse error, considering `Void` as a data type with no constructors. @since base-4.8.0.0
Instance details Defined in GHC.Internal.Read Methods readsPrec :: Int -> ReadS Void # readList :: ReadS [Void] # readPrec :: ReadPrec Void # readListPrec :: ReadPrec [Void] #
Read All | @since base-2.01
Instance details Defined in GHC.Internal.Data.Semigroup.Internal Methods readsPrec :: Int -> ReadS All # readList :: ReadS [All] # readPrec :: ReadPrec All # readListPrec :: ReadPrec [All] #
Read Any | @since base-2.01
Instance details Defined in GHC.Internal.Data.Semigroup.Internal Methods readsPrec :: Int -> ReadS Any # readList :: ReadS [Any] # readPrec :: ReadPrec Any # readListPrec :: ReadPrec [Any] #
Read Version | @since base-2.01
Instance details Defined in GHC.Internal.Data.Version Methods readsPrec :: Int -> ReadS Version # readList :: ReadS [Version] # readPrec :: ReadPrec Version # readListPrec :: ReadPrec [Version] #
Read Associativity | @since base-4.6.0.0
Instance details Defined in GHC.Internal.Generics Methods readsPrec :: Int -> ReadS Associativity # readList :: ReadS [Associativity] # readPrec :: ReadPrec Associativity # readListPrec :: ReadPrec [Associativity] #
Read DecidedStrictness | @since base-4.9.0.0
Instance details Defined in GHC.Internal.Generics Methods readsPrec :: Int -> ReadS DecidedStrictness # readList :: ReadS [DecidedStrictness] # readPrec :: ReadPrec DecidedStrictness # readListPrec :: ReadPrec [DecidedStrictness] #
Read Fixity | @since base-4.6.0.0
Instance details Defined in GHC.Internal.Generics Methods readsPrec :: Int -> ReadS Fixity # readList :: ReadS [Fixity] # readPrec :: ReadPrec Fixity # readListPrec :: ReadPrec [Fixity] #
Read SourceStrictness | @since base-4.9.0.0
Instance details Defined in GHC.Internal.Generics Methods readsPrec :: Int -> ReadS SourceStrictness # readList :: ReadS [SourceStrictness] # readPrec :: ReadPrec SourceStrictness # readListPrec :: ReadPrec [SourceStrictness] #
Read SourceUnpackedness | @since base-4.9.0.0
Instance details Defined in GHC.Internal.Generics Methods readsPrec :: Int -> ReadS SourceUnpackedness # readList :: ReadS [SourceUnpackedness] # readPrec :: ReadPrec SourceUnpackedness # readListPrec :: ReadPrec [SourceUnpackedness] #
Read ExitCode |
Instance details Defined in GHC.Internal.IO.Exception Methods readsPrec :: Int -> ReadS ExitCode # readList :: ReadS [ExitCode] # readPrec :: ReadPrec ExitCode # readListPrec :: ReadPrec [ExitCode] #
Read BufferMode | @since base-4.2.0.0
Instance details Defined in GHC.Internal.IO.Handle.Types Methods readsPrec :: Int -> ReadS BufferMode # readList :: ReadS [BufferMode] # readPrec :: ReadPrec BufferMode # readListPrec :: ReadPrec [BufferMode] #
Read Newline | @since base-4.3.0.0
Instance details Defined in GHC.Internal.IO.Handle.Types Methods readsPrec :: Int -> ReadS Newline # readList :: ReadS [Newline] # readPrec :: ReadPrec Newline # readListPrec :: ReadPrec [Newline] #
Read NewlineMode | @since base-4.3.0.0
Instance details Defined in GHC.Internal.IO.Handle.Types Methods readsPrec :: Int -> ReadS NewlineMode # readList :: ReadS [NewlineMode] # readPrec :: ReadPrec NewlineMode # readListPrec :: ReadPrec [NewlineMode] #
Read IOMode | @since base-4.2.0.0
Instance details Defined in GHC.Internal.IO.IOMode Methods readsPrec :: Int -> ReadS IOMode # readList :: ReadS [IOMode] # readPrec :: ReadPrec IOMode # readListPrec :: ReadPrec [IOMode] #
Read Int16 | @since base-2.01
Instance details Defined in GHC.Internal.Int Methods readsPrec :: Int -> ReadS Int16 # readList :: ReadS [Int16] # readPrec :: ReadPrec Int16 # readListPrec :: ReadPrec [Int16] #
Read Int32 | @since base-2.01
Instance details Defined in GHC.Internal.Int Methods readsPrec :: Int -> ReadS Int32 # readList :: ReadS [Int32] # readPrec :: ReadPrec Int32 # readListPrec :: ReadPrec [Int32] #
Read Int64 | @since base-2.01
Instance details Defined in GHC.Internal.Int Methods readsPrec :: Int -> ReadS Int64 # readList :: ReadS [Int64] # readPrec :: ReadPrec Int64 # readListPrec :: ReadPrec [Int64] #
Read Int8 | @since base-2.01
Instance details Defined in GHC.Internal.Int Methods readsPrec :: Int -> ReadS Int8 # readList :: ReadS [Int8] # readPrec :: ReadPrec Int8 # readListPrec :: ReadPrec [Int8] #
Read Lexeme | @since base-2.01
Instance details Defined in GHC.Internal.Read Methods readsPrec :: Int -> ReadS Lexeme # readList :: ReadS [Lexeme] # readPrec :: ReadPrec Lexeme # readListPrec :: ReadPrec [Lexeme] #
Read SomeNat | @since base-4.7.0.0
Instance details Defined in GHC.Internal.TypeNats Methods readsPrec :: Int -> ReadS SomeNat # readList :: ReadS [SomeNat] # readPrec :: ReadPrec SomeNat # readListPrec :: ReadPrec [SomeNat] #
Read GeneralCategory | @since base-2.01
Instance details Defined in GHC.Internal.Read Methods readsPrec :: Int -> ReadS GeneralCategory # readList :: ReadS [GeneralCategory] # readPrec :: ReadPrec GeneralCategory # readListPrec :: ReadPrec [GeneralCategory] #
Read Word16 | @since base-2.01
Instance details Defined in GHC.Internal.Read Methods readsPrec :: Int -> ReadS Word16 # readList :: ReadS [Word16] # readPrec :: ReadPrec Word16 # readListPrec :: ReadPrec [Word16] #
Read Word32 | @since base-2.01
Instance details Defined in GHC.Internal.Read Methods readsPrec :: Int -> ReadS Word32 # readList :: ReadS [Word32] # readPrec :: ReadPrec Word32 # readListPrec :: ReadPrec [Word32] #
Read Word64 | @since base-2.01
Instance details Defined in GHC.Internal.Read Methods readsPrec :: Int -> ReadS Word64 # readList :: ReadS [Word64] # readPrec :: ReadPrec Word64 # readListPrec :: ReadPrec [Word64] #
Read Word8 | @since base-2.01
Instance details Defined in GHC.Internal.Read Methods readsPrec :: Int -> ReadS Word8 # readList :: ReadS [Word8] # readPrec :: ReadPrec Word8 # readListPrec :: ReadPrec [Word8] #
Read Ordering | @since base-2.01
Instance details Defined in GHC.Internal.Read Methods readsPrec :: Int -> ReadS Ordering # readList :: ReadS [Ordering] # readPrec :: ReadPrec Ordering # readListPrec :: ReadPrec [Ordering] #
Read Undefined # |
Instance details Defined in Relude.Debug Methods readsPrec :: Int -> ReadS Undefined # readList :: ReadS [Undefined] # readPrec :: ReadPrec Undefined # readListPrec :: ReadPrec [Undefined] #
Read I8 |
Instance details Defined in Data.Text.Foreign Methods readsPrec :: Int -> ReadS I8 # readList :: ReadS [I8] # readPrec :: ReadPrec I8 # readListPrec :: ReadPrec [I8] #
Read FPFormat |
Instance details Defined in Data.Text.Lazy.Builder.RealFloat Methods readsPrec :: Int -> ReadS FPFormat # readList :: ReadS [FPFormat] # readPrec :: ReadPrec FPFormat # readListPrec :: ReadPrec [FPFormat] #
Read Integer | @since base-2.01
Instance details Defined in GHC.Internal.Read Methods readsPrec :: Int -> ReadS Integer # readList :: ReadS [Integer] # readPrec :: ReadPrec Integer # readListPrec :: ReadPrec [Integer] #
Read Natural | @since base-4.8.0.0
Instance details Defined in GHC.Internal.Read Methods readsPrec :: Int -> ReadS Natural # readList :: ReadS [Natural] # readPrec :: ReadPrec Natural # readListPrec :: ReadPrec [Natural] #
Read () | @since base-2.01
Instance details Defined in GHC.Internal.Read Methods readsPrec :: Int -> ReadS () # readList :: ReadS [()] # readPrec :: ReadPrec () # readListPrec :: ReadPrec [()] #
Read Bool | @since base-2.01
Instance details Defined in GHC.Internal.Read Methods readsPrec :: Int -> ReadS Bool # readList :: ReadS [Bool] # readPrec :: ReadPrec Bool # readListPrec :: ReadPrec [Bool] #
Read Char | @since base-2.01
Instance details Defined in GHC.Internal.Read Methods readsPrec :: Int -> ReadS Char # readList :: ReadS [Char] # readPrec :: ReadPrec Char # readListPrec :: ReadPrec [Char] #
Read Double | @since base-2.01
Instance details Defined in GHC.Internal.Read Methods readsPrec :: Int -> ReadS Double # readList :: ReadS [Double] # readPrec :: ReadPrec Double # readListPrec :: ReadPrec [Double] #
Read Float | @since base-2.01
Instance details Defined in GHC.Internal.Read Methods readsPrec :: Int -> ReadS Float # readList :: ReadS [Float] # readPrec :: ReadPrec Float # readListPrec :: ReadPrec [Float] #
Read Int | @since base-2.01
Instance details Defined in GHC.Internal.Read Methods readsPrec :: Int -> ReadS Int # readList :: ReadS [Int] # readPrec :: ReadPrec Int # readListPrec :: ReadPrec [Int] #
Read Word | @since base-4.5.0.0
Instance details Defined in GHC.Internal.Read Methods readsPrec :: Int -> ReadS Word # readList :: ReadS [Word] # readPrec :: ReadPrec Word # readListPrec :: ReadPrec [Word] #
Read a => Read (Complex a) | Since: base-2.1
Instance details Defined in Data.Complex Methods readsPrec :: Int -> ReadS (Complex a) # readList :: ReadS [Complex a] # readPrec :: ReadPrec (Complex a) # readListPrec :: ReadPrec [Complex a] #
Read a => Read (First a) | Since: base-4.9.0.0
Instance details Defined in Data.Semigroup Methods readsPrec :: Int -> ReadS (First a) # readList :: ReadS [First a] # readPrec :: ReadPrec (First a) # readListPrec :: ReadPrec [First a] #
Read a => Read (Last a) | Since: base-4.9.0.0
Instance details Defined in Data.Semigroup Methods readsPrec :: Int -> ReadS (Last a) # readList :: ReadS [Last a] # readPrec :: ReadPrec (Last a) # readListPrec :: ReadPrec [Last a] #
Read a => Read (Max a) | Since: base-4.9.0.0
Instance details Defined in Data.Semigroup Methods readsPrec :: Int -> ReadS (Max a) # readList :: ReadS [Max a] # readPrec :: ReadPrec (Max a) # readListPrec :: ReadPrec [Max a] #
Read a => Read (Min a) | Since: base-4.9.0.0
Instance details Defined in Data.Semigroup Methods readsPrec :: Int -> ReadS (Min a) # readList :: ReadS [Min a] # readPrec :: ReadPrec (Min a) # readListPrec :: ReadPrec [Min a] #
Read m => Read (WrappedMonoid m) | Since: base-4.9.0.0
Instance details Defined in Data.Semigroup Methods readsPrec :: Int -> ReadS (WrappedMonoid m) # readList :: ReadS [WrappedMonoid m] # readPrec :: ReadPrec (WrappedMonoid m) # readListPrec :: ReadPrec [WrappedMonoid m] #
Read vertex => Read (SCC vertex) | Since: containers-0.5.9
Instance details Defined in Data.Graph Methods readsPrec :: Int -> ReadS (SCC vertex) # readList :: ReadS [SCC vertex] # readPrec :: ReadPrec (SCC vertex) # readListPrec :: ReadPrec [SCC vertex] #
Read e => Read (IntMap e) |
Instance details Defined in Data.IntMap.Internal Methods readsPrec :: Int -> ReadS (IntMap e) # readList :: ReadS [IntMap e] # readPrec :: ReadPrec (IntMap e) # readListPrec :: ReadPrec [IntMap e] #
Read a => Read (Seq a) |
Instance details Defined in Data.Sequence.Internal Methods readsPrec :: Int -> ReadS (Seq a) # readList :: ReadS [Seq a] # readPrec :: ReadPrec (Seq a) # readListPrec :: ReadPrec [Seq a] #
Read a => Read (ViewL a) |
Instance details Defined in Data.Sequence.Internal Methods readsPrec :: Int -> ReadS (ViewL a) # readList :: ReadS [ViewL a] # readPrec :: ReadPrec (ViewL a) # readListPrec :: ReadPrec [ViewL a] #
Read a => Read (ViewR a) |
Instance details Defined in Data.Sequence.Internal Methods readsPrec :: Int -> ReadS (ViewR a) # readList :: ReadS [ViewR a] # readPrec :: ReadPrec (ViewR a) # readListPrec :: ReadPrec [ViewR a] #
(Read a, Ord a) => Read (Set a) |
Instance details Defined in Data.Set.Internal Methods readsPrec :: Int -> ReadS (Set a) # readList :: ReadS [Set a] # readPrec :: ReadPrec (Set a) # readListPrec :: ReadPrec [Set a] #
Read a => Read (Tree a) |
Instance details Defined in Data.Tree Methods readsPrec :: Int -> ReadS (Tree a) # readList :: ReadS [Tree a] # readPrec :: ReadPrec (Tree a) # readListPrec :: ReadPrec [Tree a] #
Read a => Read (NonEmpty a) | @since base-4.11.0.0
Instance details Defined in GHC.Internal.Read Methods readsPrec :: Int -> ReadS (NonEmpty a) # readList :: ReadS [NonEmpty a] # readPrec :: ReadPrec (NonEmpty a) # readListPrec :: ReadPrec [NonEmpty a] #
Read a => Read (Identity a) | This instance would be equivalent to the derived instances of the `Identity` newtype if the `runIdentity` field were removed @since base-4.8.0.0
Instance details Defined in GHC.Internal.Data.Functor.Identity Methods readsPrec :: Int -> ReadS (Identity a) # readList :: ReadS [Identity a] # readPrec :: ReadPrec (Identity a) # readListPrec :: ReadPrec [Identity a] #
Read a => Read (First a) | @since base-2.01
Instance details Defined in GHC.Internal.Data.Monoid Methods readsPrec :: Int -> ReadS (First a) # readList :: ReadS [First a] # readPrec :: ReadPrec (First a) # readListPrec :: ReadPrec [First a] #
Read a => Read (Last a) | @since base-2.01
Instance details Defined in GHC.Internal.Data.Monoid Methods readsPrec :: Int -> ReadS (Last a) # readList :: ReadS [Last a] # readPrec :: ReadPrec (Last a) # readListPrec :: ReadPrec [Last a] #
Read a => Read (Down a) | This instance would be equivalent to the derived instances of the `Down` newtype if the `getDown` field were removed @since base-4.7.0.0
Instance details Defined in GHC.Internal.Data.Ord Methods readsPrec :: Int -> ReadS (Down a) # readList :: ReadS [Down a] # readPrec :: ReadPrec (Down a) # readListPrec :: ReadPrec [Down a] #
Read a => Read (Dual a) | @since base-2.01
Instance details Defined in GHC.Internal.Data.Semigroup.Internal Methods readsPrec :: Int -> ReadS (Dual a) # readList :: ReadS [Dual a] # readPrec :: ReadPrec (Dual a) # readListPrec :: ReadPrec [Dual a] #
Read a => Read (Product a) | @since base-2.01
Instance details Defined in GHC.Internal.Data.Semigroup.Internal Methods readsPrec :: Int -> ReadS (Product a) # readList :: ReadS [Product a] # readPrec :: ReadPrec (Product a) # readListPrec :: ReadPrec [Product a] #
Read a => Read (Sum a) | @since base-2.01
Instance details Defined in GHC.Internal.Data.Semigroup.Internal Methods readsPrec :: Int -> ReadS (Sum a) # readList :: ReadS [Sum a] # readPrec :: ReadPrec (Sum a) # readListPrec :: ReadPrec [Sum a] #
Read a => Read (ZipList a) | @since base-4.7.0.0
Instance details Defined in GHC.Internal.Functor.ZipList Methods readsPrec :: Int -> ReadS (ZipList a) # readList :: ReadS [ZipList a] # readPrec :: ReadPrec (ZipList a) # readListPrec :: ReadPrec [ZipList a] #
Read p => Read (Par1 p) | @since base-4.7.0.0
Instance details Defined in GHC.Internal.Generics Methods readsPrec :: Int -> ReadS (Par1 p) # readList :: ReadS [Par1 p] # readPrec :: ReadPrec (Par1 p) # readListPrec :: ReadPrec [Par1 p] #
(Integral a, Read a) => Read (Ratio a) | @since base-2.01
Instance details Defined in GHC.Internal.Read Methods readsPrec :: Int -> ReadS (Ratio a) # readList :: ReadS [Ratio a] # readPrec :: ReadPrec (Ratio a) # readListPrec :: ReadPrec [Ratio a] #
(Eq a, Hashable a, Read a) => Read (HashSet a) |
Instance details Defined in Data.HashSet.Internal Methods readsPrec :: Int -> ReadS (HashSet a) # readList :: ReadS [HashSet a] # readPrec :: ReadPrec (HashSet a) # readListPrec :: ReadPrec [HashSet a] #
Read a => Read (Maybe a) | @since base-2.01
Instance details Defined in GHC.Internal.Read Methods readsPrec :: Int -> ReadS (Maybe a) # readList :: ReadS [Maybe a] # readPrec :: ReadPrec (Maybe a) # readListPrec :: ReadPrec [Maybe a] #
Read a => Read (Solo a) | @since base-4.15
Instance details Defined in GHC.Internal.Read Methods readsPrec :: Int -> ReadS (Solo a) # readList :: ReadS [Solo a] # readPrec :: ReadPrec (Solo a) # readListPrec :: ReadPrec [Solo a] #
Read a => Read [a] | @since base-2.01
Instance details Defined in GHC.Internal.Read Methods readsPrec :: Int -> ReadS [a] # readList :: ReadS [[a]] # readPrec :: ReadPrec [a] # readListPrec :: ReadPrec [[a]] #
HasResolution a => Read (Fixed a) | Since: base-4.3.0.0
Instance details Defined in Data.Fixed Methods readsPrec :: Int -> ReadS (Fixed a) # readList :: ReadS [Fixed a] # readPrec :: ReadPrec (Fixed a) # readListPrec :: ReadPrec [Fixed a] #
(Read a, Read b) => Read (Arg a b) | Since: base-4.9.0.0
Instance details Defined in Data.Semigroup Methods readsPrec :: Int -> ReadS (Arg a b) # readList :: ReadS [Arg a b] # readPrec :: ReadPrec (Arg a b) # readListPrec :: ReadPrec [Arg a b] #
(Ord k, Read k, Read e) => Read (Map k e) |
Instance details Defined in Data.Map.Internal Methods readsPrec :: Int -> ReadS (Map k e) # readList :: ReadS [Map k e] # readPrec :: ReadPrec (Map k e) # readListPrec :: ReadPrec [Map k e] #
(Ix a, Read a, Read b) => Read (Array a b) | @since base-2.01
Instance details Defined in GHC.Internal.Read Methods readsPrec :: Int -> ReadS (Array a b) # readList :: ReadS [Array a b] # readPrec :: ReadPrec (Array a b) # readListPrec :: ReadPrec [Array a b] #
(Read a, Read b) => Read (Either a b) | @since base-3.0
Instance details Defined in GHC.Internal.Data.Either Methods readsPrec :: Int -> ReadS (Either a b) # readList :: ReadS [Either a b] # readPrec :: ReadPrec (Either a b) # readListPrec :: ReadPrec [Either a b] #
Read (Proxy t) | @since base-4.7.0.0
Instance details Defined in GHC.Internal.Data.Proxy Methods readsPrec :: Int -> ReadS (Proxy t) # readList :: ReadS [Proxy t] # readPrec :: ReadPrec (Proxy t) # readListPrec :: ReadPrec [Proxy t] #
Read (U1 p) | @since base-4.9.0.0
Instance details Defined in GHC.Internal.Generics Methods readsPrec :: Int -> ReadS (U1 p) # readList :: ReadS [U1 p] # readPrec :: ReadPrec (U1 p) # readListPrec :: ReadPrec [U1 p] #
Read (V1 p) | @since base-4.9.0.0
Instance details Defined in GHC.Internal.Generics Methods readsPrec :: Int -> ReadS (V1 p) # readList :: ReadS [V1 p] # readPrec :: ReadPrec (V1 p) # readListPrec :: ReadPrec [V1 p] #
(Read1 f, Read a) => Read (Lift f a) |
Instance details Defined in Control.Applicative.Lift Methods readsPrec :: Int -> ReadS (Lift f a) # readList :: ReadS [Lift f a] # readPrec :: ReadPrec (Lift f a) # readListPrec :: ReadPrec [Lift f a] #
(Read1 m, Read a) => Read (MaybeT m a) |
Instance details Defined in Control.Monad.Trans.Maybe Methods readsPrec :: Int -> ReadS (MaybeT m a) # readList :: ReadS [MaybeT m a] # readPrec :: ReadPrec (MaybeT m a) # readListPrec :: ReadPrec [MaybeT m a] #
(Eq k, Hashable k, Read k, Read e) => Read (HashMap k e) |
Instance details Defined in Data.HashMap.Internal Methods readsPrec :: Int -> ReadS (HashMap k e) # readList :: ReadS [HashMap k e] # readPrec :: ReadPrec (HashMap k e) # readListPrec :: ReadPrec [HashMap k e] #
(Read a, Read b) => Read (a, b) | @since base-2.01
Instance details Defined in GHC.Internal.Read Methods readsPrec :: Int -> ReadS (a, b) # readList :: ReadS [(a, b)] # readPrec :: ReadPrec (a, b) # readListPrec :: ReadPrec [(a, b)] #
Read a => Read (Const a b) | This instance would be equivalent to the derived instances of the `Const` newtype if the `getConst` field were removed @since base-4.8.0.0
Instance details Defined in GHC.Internal.Data.Functor.Const Methods readsPrec :: Int -> ReadS (Const a b) # readList :: ReadS [Const a b] # readPrec :: ReadPrec (Const a b) # readListPrec :: ReadPrec [Const a b] #
Read (f a) => Read (Ap f a) | @since base-4.12.0.0
Instance details Defined in GHC.Internal.Data.Monoid Methods readsPrec :: Int -> ReadS (Ap f a) # readList :: ReadS [Ap f a] # readPrec :: ReadPrec (Ap f a) # readListPrec :: ReadPrec [Ap f a] #
Read (f a) => Read (Alt f a) | @since base-4.8.0.0
Instance details Defined in GHC.Internal.Data.Semigroup.Internal Methods readsPrec :: Int -> ReadS (Alt f a) # readList :: ReadS [Alt f a] # readPrec :: ReadPrec (Alt f a) # readListPrec :: ReadPrec [Alt f a] #
Read (f p) => Read (Rec1 f p) | @since base-4.7.0.0
Instance details Defined in GHC.Internal.Generics Methods readsPrec :: Int -> ReadS (Rec1 f p) # readList :: ReadS [Rec1 f p] # readPrec :: ReadPrec (Rec1 f p) # readListPrec :: ReadPrec [Rec1 f p] #
(Read1 f, Read a) => Read (Backwards f a) |
Instance details Defined in Control.Applicative.Backwards Methods readsPrec :: Int -> ReadS (Backwards f a) # readList :: ReadS [Backwards f a] # readPrec :: ReadPrec (Backwards f a) # readListPrec :: ReadPrec [Backwards f a] #
(Read e, Read1 m, Read a) => Read (ExceptT e m a) |
Instance details Defined in Control.Monad.Trans.Except Methods readsPrec :: Int -> ReadS (ExceptT e m a) # readList :: ReadS [ExceptT e m a] # readPrec :: ReadPrec (ExceptT e m a) # readListPrec :: ReadPrec [ExceptT e m a] #
(Read1 f, Read a) => Read (IdentityT f a) |
Instance details Defined in Control.Monad.Trans.Identity Methods readsPrec :: Int -> ReadS (IdentityT f a) # readList :: ReadS [IdentityT f a] # readPrec :: ReadPrec (IdentityT f a) # readListPrec :: ReadPrec [IdentityT f a] #
(Read w, Read1 m, Read a) => Read (WriterT w m a) |
Instance details Defined in Control.Monad.Trans.Writer.Lazy Methods readsPrec :: Int -> ReadS (WriterT w m a) # readList :: ReadS [WriterT w m a] # readPrec :: ReadPrec (WriterT w m a) # readListPrec :: ReadPrec [WriterT w m a] #
(Read w, Read1 m, Read a) => Read (WriterT w m a) |
Instance details Defined in Control.Monad.Trans.Writer.Strict Methods readsPrec :: Int -> ReadS (WriterT w m a) # readList :: ReadS [WriterT w m a] # readPrec :: ReadPrec (WriterT w m a) # readListPrec :: ReadPrec [WriterT w m a] #
Read a => Read (Constant a b) |
Instance details Defined in Data.Functor.Constant Methods readsPrec :: Int -> ReadS (Constant a b) # readList :: ReadS [Constant a b] # readPrec :: ReadPrec (Constant a b) # readListPrec :: ReadPrec [Constant a b] #
(Read1 f, Read a) => Read (Reverse f a) |
Instance details Defined in Data.Functor.Reverse Methods readsPrec :: Int -> ReadS (Reverse f a) # readList :: ReadS [Reverse f a] # readPrec :: ReadPrec (Reverse f a) # readListPrec :: ReadPrec [Reverse f a] #
(Read a, Read b, Read c) => Read (a, b, c) | @since base-2.01
Instance details Defined in GHC.Internal.Read Methods readsPrec :: Int -> ReadS (a, b, c) # readList :: ReadS [(a, b, c)] # readPrec :: ReadPrec (a, b, c) # readListPrec :: ReadPrec [(a, b, c)] #
(Read (f a), Read (g a)) => Read (Product f g a) | Since: base-4.18.0.0
Instance details Defined in Data.Functor.Product Methods readsPrec :: Int -> ReadS (Product f g a) # readList :: ReadS [Product f g a] # readPrec :: ReadPrec (Product f g a) # readListPrec :: ReadPrec [Product f g a] #
(Read (f a), Read (g a)) => Read (Sum f g a) | Since: base-4.18.0.0
Instance details Defined in Data.Functor.Sum Methods readsPrec :: Int -> ReadS (Sum f g a) # readList :: ReadS [Sum f g a] # readPrec :: ReadPrec (Sum f g a) # readListPrec :: ReadPrec [Sum f g a] #
(Read (f p), Read (g p)) => Read ((f :*: g) p) | @since base-4.7.0.0
Instance details Defined in GHC.Internal.Generics Methods readsPrec :: Int -> ReadS ((f :*: g) p) # readList :: ReadS [(f :*: g) p] # readPrec :: ReadPrec ((f :*: g) p) # readListPrec :: ReadPrec [(f :*: g) p] #
(Read (f p), Read (g p)) => Read ((f :+: g) p) | @since base-4.7.0.0
Instance details Defined in GHC.Internal.Generics Methods readsPrec :: Int -> ReadS ((f :+: g) p) # readList :: ReadS [(f :+: g) p] # readPrec :: ReadPrec ((f :+: g) p) # readListPrec :: ReadPrec [(f :+: g) p] #
Read c => Read (K1 i c p) | @since base-4.7.0.0
Instance details Defined in GHC.Internal.Generics Methods readsPrec :: Int -> ReadS (K1 i c p) # readList :: ReadS [K1 i c p] # readPrec :: ReadPrec (K1 i c p) # readListPrec :: ReadPrec [K1 i c p] #
(Read a, Read b, Read c, Read d) => Read (a, b, c, d) | @since base-2.01
Instance details Defined in GHC.Internal.Read Methods readsPrec :: Int -> ReadS (a, b, c, d) # readList :: ReadS [(a, b, c, d)] # readPrec :: ReadPrec (a, b, c, d) # readListPrec :: ReadPrec [(a, b, c, d)] #
Read (f (g a)) => Read (Compose f g a) | Since: base-4.18.0.0
Instance details Defined in Data.Functor.Compose Methods readsPrec :: Int -> ReadS (Compose f g a) # readList :: ReadS [Compose f g a] # readPrec :: ReadPrec (Compose f g a) # readListPrec :: ReadPrec [Compose f g a] #
Read (f (g p)) => Read ((f :.: g) p) | @since base-4.7.0.0
Instance details Defined in GHC.Internal.Generics Methods readsPrec :: Int -> ReadS ((f :.: g) p) # readList :: ReadS [(f :.: g) p] # readPrec :: ReadPrec ((f :.: g) p) # readListPrec :: ReadPrec [(f :.: g) p] #
Read (f p) => Read (M1 i c f p) | @since base-4.7.0.0
Instance details Defined in GHC.Internal.Generics Methods readsPrec :: Int -> ReadS (M1 i c f p) # readList :: ReadS [M1 i c f p] # readPrec :: ReadPrec (M1 i c f p) # readListPrec :: ReadPrec [M1 i c f p] #
(Read a, Read b, Read c, Read d, Read e) => Read (a, b, c, d, e) | @since base-2.01
Instance details Defined in GHC.Internal.Read Methods readsPrec :: Int -> ReadS (a, b, c, d, e) # readList :: ReadS [(a, b, c, d, e)] # readPrec :: ReadPrec (a, b, c, d, e) # readListPrec :: ReadPrec [(a, b, c, d, e)] #
(Read a, Read b, Read c, Read d, Read e, Read f) => Read (a, b, c, d, e, f) | @since base-2.01
Instance details Defined in GHC.Internal.Read Methods readsPrec :: Int -> ReadS (a, b, c, d, e, f) # readList :: ReadS [(a, b, c, d, e, f)] # readPrec :: ReadPrec (a, b, c, d, e, f) # readListPrec :: ReadPrec [(a, b, c, d, e, f)] #
(Read a, Read b, Read c, Read d, Read e, Read f, Read g) => Read (a, b, c, d, e, f, g) | @since base-2.01
Instance details Defined in GHC.Internal.Read Methods readsPrec :: Int -> ReadS (a, b, c, d, e, f, g) # readList :: ReadS [(a, b, c, d, e, f, g)] # readPrec :: ReadPrec (a, b, c, d, e, f, g) # readListPrec :: ReadPrec [(a, b, c, d, e, f, g)] #
(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) | @since base-2.01
Instance details Defined in GHC.Internal.Read Methods readsPrec :: Int -> ReadS (a, b, c, d, e, f, g, h) # readList :: ReadS [(a, b, c, d, e, f, g, h)] # readPrec :: ReadPrec (a, b, c, d, e, f, g, h) # readListPrec :: ReadPrec [(a, b, c, d, e, f, g, h)] #
(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) | @since base-2.01
Instance details Defined in GHC.Internal.Read Methods readsPrec :: Int -> ReadS (a, b, c, d, e, f, g, h, i) # readList :: ReadS [(a, b, c, d, e, f, g, h, i)] # readPrec :: ReadPrec (a, b, c, d, e, f, g, h, i) # readListPrec :: ReadPrec [(a, b, c, d, e, f, g, h, i)] #
(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) | @since base-2.01
Instance details Defined in GHC.Internal.Read Methods readsPrec :: Int -> ReadS (a, b, c, d, e, f, g, h, i, j) # readList :: ReadS [(a, b, c, d, e, f, g, h, i, j)] # readPrec :: ReadPrec (a, b, c, d, e, f, g, h, i, j) # readListPrec :: ReadPrec [(a, b, c, d, e, f, g, h, i, j)] #
(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) | @since base-2.01
Instance details Defined in GHC.Internal.Read Methods readsPrec :: Int -> ReadS (a, b, c, d, e, f, g, h, i, j, k) # readList :: ReadS [(a, b, c, d, e, f, g, h, i, j, k)] # readPrec :: ReadPrec (a, b, c, d, e, f, g, h, i, j, k) # readListPrec :: ReadPrec [(a, b, c, d, e, f, g, h, i, j, k)] #
(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) | @since base-2.01
Instance details Defined in GHC.Internal.Read Methods readsPrec :: Int -> ReadS (a, b, c, d, e, f, g, h, i, j, k, l) # readList :: ReadS [(a, b, c, d, e, f, g, h, i, j, k, l)] # readPrec :: ReadPrec (a, b, c, d, e, f, g, h, i, j, k, l) # readListPrec :: ReadPrec [(a, b, c, d, e, f, g, h, i, j, k, l)] #
(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) | @since base-2.01
Instance details Defined in GHC.Internal.Read Methods readsPrec :: Int -> ReadS (a, b, c, d, e, f, g, h, i, j, k, l, m) # readList :: ReadS [(a, b, c, d, e, f, g, h, i, j, k, l, m)] # readPrec :: ReadPrec (a, b, c, d, e, f, g, h, i, j, k, l, m) # readListPrec :: ReadPrec [(a, b, c, d, e, f, g, h, i, j, k, l, m)] #
(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) | @since base-2.01
Instance details Defined in GHC.Internal.Read Methods readsPrec :: Int -> ReadS (a, b, c, d, e, f, g, h, i, j, k, l, m, n) # readList :: ReadS [(a, b, c, d, e, f, g, h, i, j, k, l, m, n)] # readPrec :: ReadPrec (a, b, c, d, e, f, g, h, i, j, k, l, m, n) # readListPrec :: ReadPrec [(a, b, c, d, e, f, g, h, i, j, k, l, m, n)] #
(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) | @since base-2.01
Instance details Defined in GHC.Internal.Read Methods readsPrec :: Int -> ReadS (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) # readList :: ReadS [(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o)] # readPrec :: ReadPrec (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) # readListPrec :: ReadPrec [(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o)] #

reads :: Read a => ReadS a #

equivalent to `readsPrec` with a precedence of 0.

readMaybe :: Read a => String -> Maybe a #

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

    >>> readMaybe "123" :: Maybe Int
    Just 123

    >>> readMaybe "hello" :: Maybe Int
    Nothing

@since base-4.6.0.0

# Text

data Text #

A space efficient, packed, unboxed Unicode text type.

#### Instances

Instances details

Hashable Text |
Instance details Defined in Data.Hashable.Class Methods hashWithSalt :: Int -> Text -> Int # hash :: Text -> Int #
One Text # | Create singleton strict `Text`.
    >>> one 'a' :: Text
    "a"
    law> length (one x) ≡ 1
Instance details Defined in Relude.Container.One Associated Types
type OneItem Text |
Instance details Defined in Relude.Container.One type OneItem Text = Char
Methods one :: OneItem Text -> Text #
ToLText Text # |
Instance details Defined in Relude.String.Conversion Methods toLText :: Text -> LText #
ToString Text # |
Instance details Defined in Relude.String.Conversion Methods toString :: Text -> String #
ToText Text # |
Instance details Defined in Relude.String.Conversion Methods toText :: Text -> Text #
ConvertUtf8 Text ByteString # |
Instance details Defined in Relude.String.Conversion Methods encodeUtf8 :: Text -> ByteString # decodeUtf8 :: ByteString -> Text # decodeUtf8Strict :: ByteString -> Either UnicodeException Text #
ConvertUtf8 Text ShortByteString # | Since: 0.6.0.0
Instance details Defined in Relude.String.Conversion Methods encodeUtf8 :: Text -> ShortByteString # decodeUtf8 :: ShortByteString -> Text # decodeUtf8Strict :: ShortByteString -> Either UnicodeException Text #
ConvertUtf8 Text LByteString # |
Instance details Defined in Relude.String.Conversion Methods encodeUtf8 :: Text -> LByteString # decodeUtf8 :: LByteString -> Text # decodeUtf8Strict :: LByteString -> Either UnicodeException Text #
LazyStrict LText Text # |
Instance details Defined in Relude.String.Conversion Methods toLazy :: Text -> LText # toStrict :: LText -> Text #
type Item Text |
Instance details Defined in Data.Text type Item Text = Char
type OneItem Text # |
Instance details Defined in Relude.Container.One type OneItem Text = Char

lines :: 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.

    >>> 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'
    ...

unlines :: 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.

    >>> 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'
    ...

words :: 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.

    >>> 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'
    ...

unwords :: 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.

    >>> 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'
    ...

decodeUtf8With :: OnDecodeError -> ByteString -> Text #

Decode a `ByteString` containing UTF-8 encoded text.

Surrogate code points in replacement character returned by `OnDecodeError` will be automatically remapped to the replacement char `U+FFFD`.

decodeUtf8' :: ByteString -> Either UnicodeException Text #

Decode a `ByteString` containing UTF-8 encoded text.

If the input contains any invalid UTF-8 data, the relevant exception will be returned, otherwise the decoded text.

data UnicodeException #

An exception type for representing Unicode encoding errors.

#### Instances

Instances details

NFData UnicodeException |
Instance details Defined in Data.Text.Encoding.Error Methods rnf :: UnicodeException -> () #
Exception UnicodeException |
Instance details Defined in Data.Text.Encoding.Error Methods toException :: UnicodeException -> SomeException # fromException :: SomeException -> Maybe UnicodeException # displayException :: UnicodeException -> String # backtraceDesired :: UnicodeException -> Bool #
Show UnicodeException |
Instance details Defined in Data.Text.Encoding.Error Methods showsPrec :: Int -> UnicodeException -> ShowS # show :: UnicodeException -> String # showList :: [UnicodeException] -> ShowS #
Eq UnicodeException |
Instance details Defined in Data.Text.Encoding.Error Methods (==) :: UnicodeException -> UnicodeException -> Bool # (/=) :: UnicodeException -> UnicodeException -> Bool #

type OnDecodeError = OnError Word8 Char #

A handler for a decoding error.

type 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.

strictDecode :: OnDecodeError #

Throw a `UnicodeException` if decoding fails.

lenientDecode :: OnDecodeError #

Replace an invalid input byte with the Unicode replacement character U+FFFD.

# ByteString

data 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.

#### Instances

Instances details

NFData ByteString |
Instance details Defined in Data.ByteString.Internal.Type Methods rnf :: ByteString -> () #
Monoid ByteString |
Instance details Defined in Data.ByteString.Internal.Type Methods mempty :: ByteString # mappend :: ByteString -> ByteString -> ByteString # mconcat :: [ByteString] -> ByteString #
Semigroup ByteString |
Instance details Defined in Data.ByteString.Internal.Type Methods (<>) :: ByteString -> ByteString -> ByteString # sconcat :: NonEmpty ByteString -> ByteString # stimes :: Integral b => b -> ByteString -> ByteString #
Data ByteString |
Instance details Defined in Data.ByteString.Internal.Type Methods gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> ByteString -> c ByteString # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c ByteString # toConstr :: ByteString -> Constr # dataTypeOf :: ByteString -> DataType # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c ByteString) # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c ByteString) # gmapT :: (forall b. Data b => b -> b) -> ByteString -> ByteString # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> ByteString -> r # gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> ByteString -> r # gmapQ :: (forall d. Data d => d -> u) -> ByteString -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> ByteString -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> ByteString -> m ByteString # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> ByteString -> m ByteString # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> ByteString -> m ByteString #
IsString ByteString | Beware: `fromString` truncates multi-byte characters to octets. e.g. "枯朶に烏のとまりけり秋の暮" becomes �6k�nh~�Q��n�
Instance details Defined in Data.ByteString.Internal.Type Methods fromString :: String -> ByteString #
IsList ByteString | Since: bytestring-0.10.12.0
Instance details Defined in Data.ByteString.Internal.Type Associated Types
type Item ByteString |
Instance details Defined in Data.ByteString.Internal.Type type Item ByteString = Word8
Methods fromList :: [Item ByteString] -> ByteString # fromListN :: Int -> [Item ByteString] -> ByteString # toList :: ByteString -> [Item ByteString] #
Read ByteString |
Instance details Defined in Data.ByteString.Internal.Type Methods readsPrec :: Int -> ReadS ByteString # readList :: ReadS [ByteString] # readPrec :: ReadPrec ByteString # readListPrec :: ReadPrec [ByteString] #
Show ByteString |
Instance details Defined in Data.ByteString.Internal.Type Methods showsPrec :: Int -> ByteString -> ShowS # show :: ByteString -> String # showList :: [ByteString] -> ShowS #
Eq ByteString |
Instance details Defined in Data.ByteString.Internal.Type Methods (==) :: ByteString -> ByteString -> Bool # (/=) :: ByteString -> ByteString -> Bool #
Ord ByteString |
Instance details Defined in Data.ByteString.Internal.Type Methods compare :: ByteString -> ByteString -> Ordering # (<) :: ByteString -> ByteString -> Bool # (<=) :: ByteString -> ByteString -> Bool # (>) :: ByteString -> ByteString -> Bool # (>=) :: ByteString -> ByteString -> Bool # max :: ByteString -> ByteString -> ByteString # min :: ByteString -> ByteString -> ByteString #
Hashable ByteString |
Instance details Defined in Data.Hashable.Class Methods hashWithSalt :: Int -> ByteString -> Int # hash :: ByteString -> Int #
One ByteString # | Create singleton strict `ByteString`.
    >>> one 97 :: ByteString
    "a"
    law> length (one x) ≡ 1
Instance details Defined in Relude.Container.One Associated Types
type OneItem ByteString |
Instance details Defined in Relude.Container.One type OneItem ByteString = Word8
Methods one :: OneItem ByteString -> ByteString #
EncodingError ToLText "ByteString" "LText" => ToLText ByteString # | ⚠️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:
    >>> 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
    ...
Since: 0.6.0.0
Instance details Defined in Relude.String.Conversion Methods toLText :: ByteString -> LText #
EncodingError ToString "ByteString" "String" => ToString ByteString # | ⚠️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:
    >>> 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
    ...
Since: 0.6.0.0
Instance details Defined in Relude.String.Conversion Methods toString :: ByteString -> String #
EncodingError ToText "ByteString" "Text" => ToText ByteString # | ⚠️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:
    >>> 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
    ...
Since: 0.6.0.0
Instance details Defined in Relude.String.Conversion Methods toText :: ByteString -> Text #
ConvertUtf8 LText ByteString # |
Instance details Defined in Relude.String.Conversion Methods encodeUtf8 :: LText -> ByteString # decodeUtf8 :: ByteString -> LText # decodeUtf8Strict :: ByteString -> Either UnicodeException LText #
ConvertUtf8 Text ByteString # |
Instance details Defined in Relude.String.Conversion Methods encodeUtf8 :: Text -> ByteString # decodeUtf8 :: ByteString -> Text # decodeUtf8Strict :: ByteString -> Either UnicodeException Text #
ConvertUtf8 String ByteString # |
Instance details Defined in Relude.String.Conversion Methods encodeUtf8 :: String -> ByteString # decodeUtf8 :: ByteString -> String # decodeUtf8Strict :: ByteString -> Either UnicodeException String #
LazyStrict LByteString ByteString # |
Instance details Defined in Relude.String.Conversion Methods toLazy :: ByteString -> LByteString # toStrict :: LByteString -> ByteString #
Lift ByteString | Since: bytestring-0.11.2.0
Instance details Defined in Data.ByteString.Internal.Type Methods lift :: Quote m => ByteString -> m Exp # liftTyped :: forall (m :: Type -> Type). Quote m => ByteString -> Code m ByteString #
type Item ByteString |
Instance details Defined in Data.ByteString.Internal.Type type Item ByteString = Word8
type OneItem ByteString # |
Instance details Defined in Relude.Container.One type OneItem ByteString = Word8

# ShortByteString

data 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.

#### Instances

Instances details

NFData ShortByteString |
Instance details Defined in Data.ByteString.Short.Internal Methods rnf :: ShortByteString -> () #
Monoid ShortByteString |
Instance details Defined in Data.ByteString.Short.Internal Methods mempty :: ShortByteString # mappend :: ShortByteString -> ShortByteString -> ShortByteString # mconcat :: [ShortByteString] -> ShortByteString #
Semigroup ShortByteString |
Instance details Defined in Data.ByteString.Short.Internal Methods (<>) :: ShortByteString -> ShortByteString -> ShortByteString # sconcat :: NonEmpty ShortByteString -> ShortByteString # stimes :: Integral b => b -> ShortByteString -> ShortByteString #
Data ShortByteString |
Instance details Defined in Data.ByteString.Short.Internal Methods gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> ShortByteString -> c ShortByteString # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c ShortByteString # toConstr :: ShortByteString -> Constr # dataTypeOf :: ShortByteString -> DataType # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c ShortByteString) # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c ShortByteString) # gmapT :: (forall b. Data b => b -> b) -> ShortByteString -> ShortByteString # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> ShortByteString -> r # gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> ShortByteString -> r # gmapQ :: (forall d. Data d => d -> u) -> ShortByteString -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> ShortByteString -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> ShortByteString -> m ShortByteString # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> ShortByteString -> m ShortByteString # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> ShortByteString -> m ShortByteString #
IsString ShortByteString | Beware: `fromString` truncates multi-byte characters to octets. e.g. "枯朶に烏のとまりけり秋の暮" becomes �6k�nh~�Q��n�
Instance details Defined in Data.ByteString.Short.Internal Methods fromString :: String -> ShortByteString #
Generic ShortByteString |
Instance details Defined in Data.ByteString.Short.Internal Associated Types
type Rep ShortByteString |
Instance details Defined in Data.ByteString.Short.Internal type Rep ShortByteString = D1 ('MetaData "ShortByteString" "Data.ByteString.Short.Internal" "bytestring-0.12.1.0-inplace" 'True) (C1 ('MetaCons "ShortByteString" 'PrefixI 'True) (S1 ('MetaSel ('Just "unShortByteString") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 ByteArray)))
Methods from :: ShortByteString -> Rep ShortByteString x # to :: Rep ShortByteString x -> ShortByteString #
IsList ShortByteString | Since: bytestring-0.10.12.0
Instance details Defined in Data.ByteString.Short.Internal Associated Types
type Item ShortByteString |
Instance details Defined in Data.ByteString.Short.Internal type Item ShortByteString = Word8
Methods fromList :: [Item ShortByteString] -> ShortByteString # fromListN :: Int -> [Item ShortByteString] -> ShortByteString # toList :: ShortByteString -> [Item ShortByteString] #
Read ShortByteString |
Instance details Defined in Data.ByteString.Short.Internal Methods readsPrec :: Int -> ReadS ShortByteString # readList :: ReadS [ShortByteString] # readPrec :: ReadPrec ShortByteString # readListPrec :: ReadPrec [ShortByteString] #
Show ShortByteString |
Instance details Defined in Data.ByteString.Short.Internal Methods showsPrec :: Int -> ShortByteString -> ShowS # show :: ShortByteString -> String # showList :: [ShortByteString] -> ShowS #
Eq ShortByteString |
Instance details Defined in Data.ByteString.Short.Internal Methods (==) :: ShortByteString -> ShortByteString -> Bool # (/=) :: ShortByteString -> ShortByteString -> Bool #
Ord ShortByteString | Lexicographic order.
Instance details Defined in Data.ByteString.Short.Internal Methods compare :: ShortByteString -> ShortByteString -> Ordering # (<) :: ShortByteString -> ShortByteString -> Bool # (<=) :: ShortByteString -> ShortByteString -> Bool # (>) :: ShortByteString -> ShortByteString -> Bool # (>=) :: ShortByteString -> ShortByteString -> Bool # max :: ShortByteString -> ShortByteString -> ShortByteString # min :: ShortByteString -> ShortByteString -> ShortByteString #
Hashable ShortByteString |
Instance details Defined in Data.Hashable.Class Methods hashWithSalt :: Int -> ShortByteString -> Int # hash :: ShortByteString -> Int #
One ShortByteString # | Create singleton `ShortByteString`.
    >>> one 97 :: ShortByteString
    "a"
    law> length (one x) ≡ 1
Instance details Defined in Relude.Container.One Associated Types
type OneItem ShortByteString |
Instance details Defined in Relude.Container.One type OneItem ShortByteString = Word8
Methods one :: OneItem ShortByteString -> ShortByteString #
EncodingError ToLText "ShortByteString" "LText" => ToLText ShortByteString # | ⚠️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:
    >>> 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
    ...
Since: 0.6.0.0
Instance details Defined in Relude.String.Conversion Methods toLText :: ShortByteString -> LText #
EncodingError ToString "ShortByteString" "String" => ToString ShortByteString # | ⚠️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:
    >>> 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
    ...
Since: 0.6.0.0
Instance details Defined in Relude.String.Conversion Methods toString :: ShortByteString -> String #
EncodingError ToText "ShortByteString" "Text" => ToText ShortByteString # | ⚠️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:
    >>> 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
    ...
Since: 0.6.0.0
Instance details Defined in Relude.String.Conversion Methods toText :: ShortByteString -> Text #
ConvertUtf8 LText ShortByteString # | Since: 0.6.0.0
Instance details Defined in Relude.String.Conversion Methods encodeUtf8 :: LText -> ShortByteString # decodeUtf8 :: ShortByteString -> LText # decodeUtf8Strict :: ShortByteString -> Either UnicodeException LText #
ConvertUtf8 Text ShortByteString # | Since: 0.6.0.0
Instance details Defined in Relude.String.Conversion Methods encodeUtf8 :: Text -> ShortByteString # decodeUtf8 :: ShortByteString -> Text # decodeUtf8Strict :: ShortByteString -> Either UnicodeException Text #
ConvertUtf8 String ShortByteString # | Since: 0.6.0.0
Instance details Defined in Relude.String.Conversion Methods encodeUtf8 :: String -> ShortByteString # decodeUtf8 :: ShortByteString -> String # decodeUtf8Strict :: ShortByteString -> Either UnicodeException String #
Lift ShortByteString |
Instance details Defined in Data.ByteString.Short.Internal Methods lift :: Quote m => ShortByteString -> m Exp # liftTyped :: forall (m :: Type -> Type). Quote m => ShortByteString -> Code m ShortByteString #
type Rep ShortByteString |
Instance details Defined in Data.ByteString.Short.Internal type Rep ShortByteString = D1 ('MetaData "ShortByteString" "Data.ByteString.Short.Internal" "bytestring-0.12.1.0-inplace" 'True) (C1 ('MetaCons "ShortByteString" 'PrefixI 'True) (S1 ('MetaSel ('Just "unShortByteString") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 ByteArray)))
type Item ShortByteString |
Instance details Defined in Data.ByteString.Short.Internal type Item ShortByteString = Word8
type OneItem ShortByteString # |
Instance details Defined in Relude.Container.One type OneItem ShortByteString = Word8

toShort :: ByteString -> ShortByteString #

O(n). Convert a `ByteString` into a `ShortByteString`.

This makes a copy, so does not retain the input string.

fromShort :: ShortByteString -> ByteString #

O(n). Convert a `ShortByteString` into a `ByteString`.