| Safe Haskell | Safe |
|---|---|
| Language | Haskell2010 |
Relude.String.Conversion
Description
This module implements type class which allow to have conversion to and
from Text, String and ByteString types (including both strict and lazy
versions). Usually you need to export Text modules qualified and use
pack / unpack functions to convert to/from Text. Now you can
just use toText / toString functions.
Synopsis
- type LText = Text
- type LByteString = ByteString
- class ConvertUtf8 a b where
- class ToString a where
- class ToLText a where
- class ToText a where
- class LazyStrict l s | l -> s, s -> l where
- fromLazy :: LazyStrict l s => l -> s
- fromStrict :: LazyStrict l s => s -> l
- readEither :: (ToString a, Read b) => a -> Either Text b
- show :: forall b a. (Show a, IsString b) => a -> b
Convenient type aliases
type LByteString = ByteString #
Type synonym for ByteString.
Conversion type classes
class ConvertUtf8 a b where #
Type class for conversion to utf8 representation of text.
Minimal complete definition
Methods
encodeUtf8 :: a -> b #
Encode as utf8 string (usually ByteString).
>>>encodeUtf8 @Text @ByteString "патак""\208\191\208\176\209\130\208\176\208\186"
decodeUtf8 :: b -> a #
Decode from utf8 string.
>>>decodeUtf8 @Text @ByteString "\208\191\208\176\209\130\208\176\208\186""\1087\1072\1090\1072\1082">>>putStrLn $ decodeUtf8 @Text @ByteString "\208\191\208\176\209\130\208\176\208\186"патак
decodeUtf8Strict :: b -> Either UnicodeException a #
Decode as utf8 string but returning execption if byte sequence is malformed.
>>>decodeUtf8 @Text @ByteString "\208\208\176\209\130\208\176\208\186""\65533\1072\1090\1072\1082"
>>>decodeUtf8Strict @Text @ByteString "\208\208\176\209\130\208\176\208\186"Left Cannot decode byte '\xd0': Data.Text.Internal.Encoding.decodeUtf8: Invalid UTF-8 stream
Instances
Type class for converting other strings to String.
Minimal complete definition
Type class for converting other strings to Text.
Minimal complete definition
Type class for converting other strings to Text.
Minimal complete definition
class LazyStrict l s | l -> s, s -> l where #
Type class for lazy-strict conversions.
Instances
| LazyStrict LByteString ByteString # | |
Defined in Relude.String.Conversion | |
| LazyStrict LText Text # | |
fromLazy :: LazyStrict l s => l -> s #
fromStrict :: LazyStrict l s => s -> l #
Show and read functions
readEither :: (ToString a, Read b) => a -> Either Text b #
Polymorhpic version of readEither.
>>>readEither @Text @Int "123"Right 123>>>readEither @Text @Int "aa"Left "Prelude.read: no parse"