Type synonym for Text.
Modulerelude-1.2.0.0Haskell2010
Relude.String.Conversion
SPDX-License-Identifier : MIT Maintainer : Kowainik xrom.xkov@gmail.com Stability : Stable Portability : Portable
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.
- 2 types
- 5 classes
- 4 values
- Packagerelude-1.2.0.0
- Exports11
- LanguageHaskell2010
- LicenceMIT
- SourceConversion.hs
Convenient type aliases
2 declarationsType synonym for ByteString.
Conversion type classes
7 declarationsType class for conversion to utf8 representation of text.
Methods
encodeUtf8 :: a -> bEncode as utf8 string (usually
B.ByteString).Example1 expression encodeUtf8 @Text @ByteString "патак""\208\191\208\176\209\130\208\176\208\186"
decodeUtf8 :: b -> aDecode from utf8 string.
Example2 expressions decodeUtf8 @Text @ByteString "\208\191\208\176\209\130\208\176\208\186""\1087\1072\1090\1072\1082"putTextLn $ decodeUtf8 @Text @ByteString "\208\191\208\176\209\130\208\176\208\186"патак
decodeUtf8Strict :: b -> Either UnicodeException aDecode as utf8 string but returning execption if byte sequence is malformed.
Example1 expression decodeUtf8 @Text @ByteString "\208\208\176\209\130\208\176\208\186""\65533\1072\1090\1072\1082"
Example1 expression decodeUtf8Strict @Text @ByteString "\208\208\176\209\130\208\176\208\186"Left Cannot decode byte '\xd0': Data.Text.Internal.Encoding: Invalid UTF-8 stream
Instances9ConvertUtf8, …
ConvertUtf8 String ByteStringDefined in relude-1.2.0.0 · Relude.String.ConversionConvertUtf8 String ShortByteStringDefined in relude-1.2.0.0 · Relude.String.ConversionConvertUtf8 String LByteStringDefined in relude-1.2.0.0 · Relude.String.ConversionConverting String to ByteString might be a slow operation. Consider using lazy bytestring at first place.
ConvertUtf8 LText ByteStringDefined in relude-1.2.0.0 · Relude.String.ConversionConvertUtf8 LText ShortByteStringDefined in relude-1.2.0.0 · Relude.String.ConversionConvertUtf8 LText LByteStringDefined in relude-1.2.0.0 · Relude.String.ConversionConvertUtf8 Text ByteStringDefined in relude-1.2.0.0 · Relude.String.ConversionConvertUtf8 Text ShortByteStringDefined in relude-1.2.0.0 · Relude.String.ConversionConvertUtf8 Text LByteStringDefined in relude-1.2.0.0 · Relude.String.Conversion
Instances6ToText
EncodingError ToTextDefined in relude-1.2.0.0 · Relude.String.Conversion"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:
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...
EncodingError ToTextDefined in relude-1.2.0.0 · Relude.String.Conversion"LByteString"
"Text"
=> ToText LByteString⚠️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" :: LByteString)...... Type 'LByteString' doesn't have instance of 'ToText'. Use 'decodeUtf8' or 'decodeUtf8Strict' to convert from UTF-8: decodeUtf8 :: LByteString -> Text decodeUtf8Strict :: LByteString -> Either UnicodeException Text...
EncodingError ToTextDefined in relude-1.2.0.0 · Relude.String.Conversion"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:
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...
ToText StringDefined in relude-1.2.0.0 · Relude.String.ConversionToText LTextDefined in relude-1.2.0.0 · Relude.String.ConversionToText TextDefined in relude-1.2.0.0 · Relude.String.Conversion
Instances6ToLText
EncodingError ToLTextDefined in relude-1.2.0.0 · Relude.String.Conversion"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:
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 ToLTextDefined in relude-1.2.0.0 · Relude.String.Conversion"LByteString"
"LText"
=> ToLText LByteString⚠️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" :: LByteString)...... Type 'LByteString' doesn't have instance of 'ToLText'. Use 'decodeUtf8' or 'decodeUtf8Strict' to convert from UTF-8: decodeUtf8 :: LByteString -> LText decodeUtf8Strict :: LByteString -> Either UnicodeException LText...
EncodingError ToLTextDefined in relude-1.2.0.0 · Relude.String.Conversion"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:
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...
ToLText StringDefined in relude-1.2.0.0 · Relude.String.ConversionToLText TextDefined in relude-1.2.0.0 · Relude.String.ConversionToLText TextDefined in relude-1.2.0.0 · Relude.String.Conversion
Instances6ToString
EncodingError ToStringDefined in relude-1.2.0.0 · Relude.String.Conversion"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:
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 ToStringDefined in relude-1.2.0.0 · Relude.String.Conversion"LByteString"
"String"
=> ToString LByteString⚠️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" :: LByteString)...... Type 'LByteString' doesn't have instance of 'ToString'. Use 'decodeUtf8' or 'decodeUtf8Strict' to convert from UTF-8: decodeUtf8 :: LByteString -> String decodeUtf8Strict :: LByteString -> Either UnicodeException String...
EncodingError ToStringDefined in relude-1.2.0.0 · Relude.String.Conversion"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:
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...
ToString StringDefined in relude-1.2.0.0 · Relude.String.ConversionToString LTextDefined in relude-1.2.0.0 · Relude.String.ConversionToString TextDefined in relude-1.2.0.0 · Relude.String.Conversion
Instances2LazyStrict
LazyStrict LByteString ByteStringDefined in relude-1.2.0.0 · Relude.String.ConversionLazyStrict LText TextDefined in relude-1.2.0.0 · Relude.String.Conversion
Alias for toStrict function.
Alias for toLazy function.
Show and read functions
2 declarationsVersion of readEither that returns Text in case of the parse error.
readEither @Int "123"Right 123readEither @Int "aa"Left "Prelude.read: no parse"
Generalized version of show. Unlike show this function
is polymorphic in its result type. This makes it more convenient to work with
data types like Text or ByteString. However, if you
pass the result of show to a function that expects polymorphic argument, this
can break type inference, so use -XTypeApplications to specify the textual
type explicitly.
show (42 :: Int)"42"show (42 :: Double)"42.0"print (show @Text True)"True"